DXF/es

Historia del fondo

The Drawing Exchange Format (DXF) is a proprietary CAD data format developed by Autodesk to enable file exchange between their flagship AutoCAD product and other software. There are a number of good software libraries for reading/writing the DXF format.

There are many versions of the DXF format. You will hear of certain key versions, such as R12 (from 1992) or R14 (from 1997 which had splines). Later versions of DXF have 3D elements, but these are rarely used or implemented. How you use DXF to share CAD data between programs depends mainly on the limitations and bugs in the corresponding readers/importers and writers/exporters. These are rarely fully documented and can be a great source of frustration.

If you are editing DXF files and want them to remain almost the same when you save them, we recommend you use LibreCAD or QCad because these programs' internal data structures are compatible with the objects in the DXF file.

In FreeCAD the DXF readers must translate the geometry (e.g., spline shapes) from the DXF file into the specific internal representations of the Workbench.

Methods for importing DXF to FreeCAD

If you intend to review the settings frequently, we recommend you go to Edit → Preferences → Import-Export → DXF and tick the box "[ ] Show this dialog when importing and exporting".

More information is on the pages Draft DXF and FreeCAD and DXF Import.

If you are using the imported geometry to build 3D shapes in the Part Design Workbench, try the Sketcher Validate after you have imported the DXF into a sketch.

C++ DXF importer

This implementation of fast, but skips features it doesn't recognize, such as DXF splines. It also can only import geometry into the Draft Workbench as individual entries in the Model tree. These can have the colors read from the file if you tick to enable this option. For further information, see this forum post.

Python DXF importer

This importer has to be downloaded and installed before it can be used. Use the "[ ] Allow FreeCAD to automatically download and update the DXF libraries" option.

This importer has more features (such as implementing splines), and has the option of loading the DXF shapes into the Sketcher Workbench. However, be warned that all the elements of the sketch will appear individually a second time in the model tree, which can be confusing. You can delete all these individual objects and retain the single sketch (which appears as the second entry in the list of new elements).

Unfortunately, the Sketcher Workbench does not implement colors, so all the geometry will appear on the same level, which is a problem if the file contains many construction lines. One work-around is to open your drawing in LibreCAD, and delete all the geometry you don't want to appear before saving a file that contains exactly the geometry that you want to load.

Macros

Keep an eye out on the FreeCAD forum or in the Macros recipes for alternative implementations of DXF importing and cleaning up as they develop.

Saving DXF

In addition to the options under the Edit → Preferences, the TechDraw Workbench can also export drawing pages to DXF using the TechDraw ExportPageDXF function.


DXF terms and definitions

Anonymous blocks

When discussing DXF files, several terms are used to describe blocks that are generated automatically by the CAD software rather than by the user.

Essentially, "anonymous block" is the technical name, "system block" describes its function, and "hidden block" describes its typical user interface behavior. For practical purposes in the context of the FreeCAD DXF importer, they all refer to the same category of blocks.

Classes of anonymous blocks

Anonymous blocks are further categorized based on the character that follows the initial asterisk. This prefix indicates the block's specific purpose. The most common classes are:

BLOCKs and INSERTs

The BLOCK entity

A BLOCK is a named collection of geometric entities (lines, arcs, polylines, etc.) that are grouped together to form a single object definition. It can be thought of as a template.

A BLOCK:

The INSERT entity

An INSERT entity is what places a copy, or instance, of a BLOCK's geometry into the drawing's model space or paper space. It is a very lightweight entity because it does not contain the geometry itself; it only contains a reference to a BLOCK definition and instructions on how to place and transform it.

An INSERT:

BLOCK placement strategies

A DXF file separates the definition of a component from its placement.

There are two primary workflows for using blocks and inserts:

  1. Template and instance workflow: A single BLOCK definition is created, and multiple INSERT entities are used to place instances of it throughout the drawing. This is an efficient method for handling repetitive elements. For instance, the geometry for a chair is defined once in a BLOCK and then referenced many times by INSERT entities.
  2. Compound object workflow: A BLOCK is created from existing geometry simply to group those objects together as a single, selectable unit. In this case, the BLOCK definition is used by a single INSERT entity only.

The DXF importer must be able to distinguish between these two use cases to correctly represent the original drawing's intent, either by creating many linked instances to a single base object (template model) or by creating a single, visible object (grouped object model).