Drawing

class Drawing

The Drawing object manages all the necessary sections, like header, tables and blocks. The tables-attribute contains the layers, styles, linetypes and other tables.

Drawing.__init__(name='noname.dxf')
Parameters:name (str) – filename of drawing

Methods

Drawing.add(entity)

Add an entity to drawing.

shortcut for: Drawing.entities.add()

Drawing.save()

Write DXF data to file-system.

Drawing.saveas(name)

Set new filename and write DXF data to file-system.

Drawing.add_layer(name, **kwargs)

Define a new layer. For valid keyword args see: LAYER

Drawing.add_style(name, **kwargs)

Define a new text-style. For valid keyword args see: TEXTSTYLE

Drawing.add_linetype(name, **kwargs)

Define a new linetype. For valid keyword args see: LINETYPE

Drawing.add_view(name, **kwargs)

Define a new view. For valid keyword args see: VIEW

Drawing.add_viewport(name, **kwargs)

Define a new viewport. For valid keyword args see: VIEWPORT (Table Entry)

Drawing.add_xref(filepath, insert=(0., 0., 0.), layer='0')

Create a simple XREF reference, filepath is the referenced drawing and insert is the insertion point.

Attributes

the header section, see HEADER Section

modelspace

Provides only a add method for adding entities to the modelspace, does the same as the add() method of the drawing object, except it garantees the paper_space attribute of the added entity is '0'.

paperspace

Provides only a add method for adding entities to the paperspace, does the same as the add() method of the drawing object, except it garantees the paper_space attribute of the added entity is '1'.

Warning

DXF R12 supports only one paperspace.

usage:

from dxfwrite import DXFEngine as dxf

drawing = dxf.drawing(name='test.dxf')
drawing.paperspace.add(dxf.text('Text in paperspace'))
drawing.modelspace.add(dxf.text('Text in modelspace'))
drawing.add(dxf.text('Text also in paperspace', insert=(0, 1), paper_space=1))
drawing.add(dxf.text('Text also in modelspace', insert=(0, 1)))
blocks

the blocks section, see BLOCK definition.

usage:

from dxfwrite import DXFEngine as dxf

drawing = dxf.drawing(name='test.dxf')
drawing.add_layer('LINES')
drawing.add(dxf.line((0, 0), (10, 0), layer='LINES')))

# set header vars, see dxf documentation for header var explanation.
# set string
drawing.header['$CLAYER'] = 'CurrentLayer'

# set int/float
drawing.header['$ANGBASE'] = 30

# set 3D Point
drawing.header['$EXTMIN'] = (0, 0, -10)
drawing.header['$EXTMAX'] = (100, 100, 50)

# add a block definition to the drawing
drawing.blocks.add(blockdef)