Tutorial for Creating DXF Drawings

Create a new DXF document by the ezdxf.new() function:

import ezdxf

# create a new DXF R2010 document
doc = ezdxf.new("R2010")

# add new entities to the modelspace
msp = doc.modelspace()
# add a LINE entity
msp.add_line((0, 0), (10, 0))
# save the DXF document
doc.saveas("line.dxf")

New entities are always added to layouts, a layout can be the modelspace, a paperspace layout or a block layout.

Predefined Resources

Ezdxf creates new DXF documents with as little content as possible, this means only the resources that are absolutely necessary are created. The ezdxf.new() function can create some standard resources, such as linetypes and text styles, by setting the argument setup to True.

import ezdxf

doc = ezdxf.new("R2010", setup=True)
msp = doc.modelspace()
msp.add_line((0, 0), (10, 0), dxfattribs={"linetype": "DASHED"})

The defined standard linetypes are shown in the basic concept section for Linetypes and the available text styles are shown in the Tutorial for Text.

Important

To see the defined text styles in a DXF viewer or CAD application, the applications have to know where the referenced TTF fonts can be found. This configuration is not possible by ezdxf and has to be done for each application as described in their documentation.

See also: Font Resources

Simple DXF R12 drawings

The r12writer add-on creates simple DXF R12 drawings with a restricted set of DXF types: LINE, CIRCLE, ARC, TEXT, POINT, SOLID, 3DFACE and POLYLINE.

The advantage of the r12writer is the speed and the small memory footprint, all entities are written directly to a file or stream without creating a document structure in memory.

See also

r12writer