DXF File Structure¶
A Drawing Interchange File is simply an ASCII text file with a file type of .dxf and specially formatted text. The overall organization of a DXF file is as follows:
- HEADER - General information about the drawing is found in this section of the DXF file. Each parameter has a variable name and an associated value.
- CLASSES - This section holds the information for application-defined classes. This section was introduced with AC1015 and can usually be ignored.
- TABLES - This section contains definitions of named items.
- Linetype table (LTYPE)
- Layer table (LAYER)
- Text Style table (STYLE)
- View table (VIEW)
- User Coordinate System table (UCS)
- Viewport configuration table (VPORT)
- Dimension Style table (DIMSTYLE)
- Application Identification table (APPID)
- BLOCKS - This section contains Block Definition entities describing the entities that make up each Block in the drawing.
- ENTITIES - This section contains the drawing entities, including any Block References.
- OBJECTS - non-graphical objects
- THUMBNAILIMAGE - This section contains a preview image of the DXF file, it is optional and can usually be ignored.
- END OF FILE
By using ezdxf you don’t have to know much about this details, but interested users can look at the original DXF Reference.
Minimal DXF Content¶
The DXF format R12 (AC1009) and prior requires just an ENTITIES section:
0 SECTION 2 ENTITIES 0 ENDSEC 0 EOF
DXF R13/14 and later¶
DXF version R13/14 and later need much more DXF content than DXF version R12.
Required sections: HEADER, CLASSES, TABLES, ENTITIES, OBJECTS
The HEADER section requires two entries:
The CLASSES section can be empty, but some DXF entities requires class definitions to work in AutoCAD.
The TABLES section requires following tables:
- VPORT with at least an entry called
- LTYPE with at least the following line types defined:
- LAYER with at least an entry for layer
- STYLE with at least an entry for style
- VIEW can be empty
- UCS can be empty
- APPID with at least an entry for
- DIMSTYLE with at least an entry for style
- BLOCK_RECORDS with two entries:
The BLOCKS section requires two BLOCKS:
The ENTITIES section can be empty.
The OBJECTS section requires following entities:
- DICTIONARY - the root dict
- one entry
ACAD_GROUPcan be empty
Minimal DXF to download: https://bitbucket.org/mozman/ezdxf/downloads/Minimal_DXF_AC1021.dxf