DXF File Structure¶
A Drawing Interchange File is simply an ASCII text file with a file type of .dxf and special formatted text. The basic file structure are DXF tags, a DXF tag consist of a DXF group code as an integer value on its own line and a the DXF value on the following line. In the ezdxf documentation DXF tags will be written as (group code, value).
For more information about DXF tags see: DXF Tags
A usual DXF file is organized in sections, starting with the DXF tag (0, ‘SECTION’) and ending with the DXF tag (0, ‘ENDSEC’). The (0, ‘EOF’) tag signals the end of file.
- 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 - holds the information for application defined classes. (DXF13 and later)
- TABLES - contains definitions of named items.
- Linetype table (LTYPE)
- Layer table (LAYER)
- Text Style table (STYLE)
- View table (VIEW): (IMHO) layout of the CAD working space, only interesting for interactive CAD applications
- Viewport configuration table (VPORT): The VPORT table is unique in that it may contain several entries
with the same name (indicating a multiple-viewport configuration). The entries corresponding to the
active viewport configuration all have the name
*ACTIVE. The first such entry describes the current viewport.
- Dimension Style table (DIMSTYLE)
- User Coordinate System table (UCS) (IMHO) only interesting for interactive CAD applications
- Application Identification table (APPID): Table of names for all applications registered with a drawing.
- Block Record table (BLOCK_RECORD) (DXF R13 and Later)
- BLOCKS - contains all block definitions. A block definition defines the content of a block.
The block name
*MODEL_SPACEis reserved for the drawing model space and the block name
*PAPER_SPACEis reserved for the active paper space layout. Both block definitions are empty, the content of the model space and the active paper space is stored in the ENTITIES section. The entities of other layouts are stored in special block definitions called
*Paper_Spacennn, nnn is an arbitrary but unique number.
- ENTITIES - contains the drawing entities of the model space and the active paper space layout. Entities of other layouts are stored in the BLOCKS sections.
- OBJECTS - non-graphical objects (DXF R13 and later)
- THUMBNAILIMAGE - contains a preview image of the DXF file, it is optional and can usually be ignored. (DXF R13 and later)
- ACDSDATA (DXF R2013 and later) - no information in the DXF reference about this section
- END OF FILE
For further information read the original DXF Reference.
Structure a usual DXF R12 file:
0 (Begin HEADER section) SECTION 2 HEADER <<<<Header variable items go here>>>> 0 ENDSEC (End HEADER section) 0 (Begin TABLES section) SECTION 2 TABLES 0 TABLE 2 VPORT 70 (viewport table maximum item count) <<<<viewport table items go here>>>> 0 ENDTAB 0 TABLE 2 APPID, DIMSTYLE, LTYPE, LAYER, STYLE, UCS, VIEW, or VPORT 70 (Table maximum item count) <<<<Table items go here>>>> 0 ENDTAB 0 ENDSEC (End TABLES section) 0 (Begin BLOCKS section) SECTION 2 BLOCKS <<<<Block definition entities go here>>>> 0 ENDSEC (End BLOCKS section) 0 (Begin ENTITIES section) SECTION 2 ENTITIES <<<<Drawing entities go here>>>> 0 ENDSEC (End ENTITIES section) 0 EOF (End of file)
Minimal DXF Content¶
Contrary to the previous chapter, the DXF R12 format (AC1009) and prior requires just the ENTITIES section:
0 SECTION 2 ENTITIES 0 ENDSEC 0 EOF
DXF R13/14 and later¶
DXF version R13/14 and later needs 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