1. Products
  2.   CAD
  3.   Java
  4.   DXFOperator
 
  

Free Java Library to Create & Manage AutoCAD DXF File

Open Source Java CAD Library allows Developers to Create, Modify, Read, Manipulate and Convert AutoCAD DXF Files to SVG, Work with Layers and Entities of Diagrams.

What is DXFOperator Library?

DXF (Drawing Exchange Format) is a widely used file format developed by Autodesk for representing two-dimensional and three-dimensional drawings. In the world of software development, leveraging open-source libraries can significantly accelerate the creation of robust and efficient applications. One such powerful tool is the Java DXFOperator Library, an open-source project available on GitHub. This library provides developers with the tools to read, write, and manipulate DXF (Drawing Exchange Format) files, a widely used format in CAD (Computer-Aided Design) applications. It provides a simple and efficient way to create DXF files without requiring AutoCAD. It supports various basic and advanced features, such as creating DXF files dynamically, manipulating, converting DXF files into SVG, DXF entities, adding text to shapes to drawings, organizing entities into layers, export DXF files and many more.

The Java DXFOperator Library is a lightweight library designed to simplify working with DXF files in Java applications. DXF files are commonly used in engineering, architecture, and design industries to exchange data between CAD software. However, parsing and manipulating DXF files can be complex due to their structure and the variety of entities they can contain. As an open-source project, the library can be extended and modified to meet specific requirements, providing flexibility for developers. The DXFOperator Library abstracts this complexity, providing developers with an intuitive API to interact with DXF files programmatically. With support for geometric entities, layer management, and AutoCAD compatibility, the library provides a robust solution for Java developers working with DXF files.

Previous Next

Getting Started with DXFOperator

The recommend way to install DXFOperator is using GitHub. Please use the following command for a smooth installation.

Install DXFOperator via GitHub

 git clone https://github.com/my88480/DXFOperator.git  

You can also install it manually; download the latest release files directly from GitHub repository.

Create DXF Drawings via Java API

The open source DXFOperator library has provided complete functionality for programmatically creating, modifying, manipulating and converting DXF files inside Java applications. The library supports a wide range of DXF entities, including lines, circles, arcs, polygons, and text, ensuring accurate conversion of complex designs. Here is a very useful example that demonstrates how to create a DXF file and add basic entities using Java commands.

How to Create a DXF File and Add Basic Entities to It via Java API?

import dxf.DXF;
import dxf.entities.EntLine;
import java.io.IOException;

public class DXFExample {
    public static void main(String[] args) {
        DXF dxf = new DXF();
        
        // Add a simple line to the DXF file
        EntLine line = new EntLine(10, 10, 100, 100);
        dxf.addEntity(line);

        // Save the DXF file
        try {
            dxf.saveAs("example.dxf");
            System.out.println("DXF file created successfully.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Manage Entities in DXF Files via Java

The DXFOperator library provides a rich set of classes for working with various DXF entities inside Java applications. The library supports entities like lines, circles, arcs, polygons and so on. With just a couple of lines of Java code software developers can easily create, modify, read, manipulate or delete entities within a DXF file. The following example shows how to modify the radius of all circle entities in a DXF files inside Java applications.

How to Modify the Radius of All Circle Entities in the DXF File via Java API?

import com.github.my88480.dxfoperator.DXFOperator;
import com.github.my88480.dxfoperator.DXFDocument;
import com.github.my88480.dxfoperator.entities.DXFCircle;

public class ModifyEntityExample {
    public static void main(String[] args) {
        // Load a DXF file
        DXFDocument document = DXFOperator.readDXF("example.dxf");

        // Find and modify a circle entity
        document.getEntities().stream()
            .filter(entity -> entity instanceof DXFCircle)
            .forEach(entity -> {
                DXFCircle circle = (DXFCircle) entity;
                circle.setRadius(50); // Change the radius of the circle
            });

        // Save the modified document
        DXFOperator.writeDXF("modified_example.dxf", document);
    }
}

Working with Layers in DXF File via Java

The open source DXFOperator library has provided complete support for handling layers inside DXF drawings inside Java applications. The library fully support working with layers which is a critical feature in CAD applications. Software Developers can create, modify, or delete layers programmatically. The following example demonstrates how to create a new layer and assign an entity to it inside Java applications.

How to Create a New Layer and Assign an Entity to It via Java API?

import com.github.my88480.dxfoperator.DXFOperator;
import com.github.my88480.dxfoperator.DXFDocument;
import com.github.my88480.dxfoperator.entities.DXFLayer;

public class LayerExample {
    public static void main(String[] args) {
        // Load a DXF file
        DXFDocument document = DXFOperator.readDXF("example.dxf");

        // Create a new layer
        DXFLayer newLayer = new DXFLayer("MyLayer");
        document.addLayer(newLayer);

        // Assign an entity to the new layer
        document.getEntities().get(0).setLayer(newLayer);

        // Save the modified document
        DXFOperator.writeDXF("layered_example.dxf", document);
    }
}

DXF File Conversion via Java

The open source DXFOperator library makes it easy for software developers to load and read DXF files. The library provides a straightforward way to convert DXF files to other supported file formats, preserving the design's structure and details. Developers can customize the output to suit their needs, such as adjusting scaling, colors, and other attributes.