Drawing Object¶
-
class
ezdxf.document.
Drawing
¶ The
Drawing
class manages all entities and tables related to a DXF drawing.-
dxfversion
¶ Actual DXF version like
'AC1009'
, set byezdxf.new()
orezdxf.readfile()
.For supported DXF versions see Document Management
-
acad_release
¶ The AutoCAD release name like
'R12'
or'R2000'
for actualdxfversion
.
-
encoding
¶ Text encoding of
Drawing
, the default encoding for new drawings is'cp1252'
. Starting with DXF R2007 (AC1021), DXF files are written as UTF-8 encoded text files, regardless of the attributeencoding
. The text encoding can be changed to encodings listed below.see also: DXF File Encoding
supported encodings 'cp874'
Thai 'cp932'
Japanese 'gbk'
UnifiedChinese 'cp949'
Korean 'cp950'
TradChinese 'cp1250'
CentralEurope 'cp1251'
Cyrillic 'cp1252'
WesternEurope 'cp1253'
Greek 'cp1254'
Turkish 'cp1255'
Hebrew 'cp1256'
Arabic 'cp1257'
Baltic 'cp1258'
Vietnam
-
output_encoding
¶ Returns required output encoding for saving to filesystem or encoding to binary data.
-
filename
¶ Drawing
filename, if loaded byezdxf.readfile()
elseNone
.
-
rootdict
¶ Reference to the root dictionary of the OBJECTS section.
-
header
¶ Reference to the
HeaderSection
, get/set drawing settings as header variables.
-
entities
¶ Reference to the
EntitySection
of the drawing, where all graphical entities are stored, but only from modelspace and the active paperspace layout. Just for your information: Entities of other paperspace layouts are stored asBlockLayout
in theBlocksSection
.
-
objects
¶ Reference to the objects section, see also
ObjectsSection
.
-
blocks
¶ Reference to the blocks section, see also
BlocksSection
.
-
tables
¶ Reference to the tables section, see also
TablesSection
.
-
classes
¶ Reference to the classes section, see also
ClassesSection
.
-
groups
¶ Collection of all groups, see also
GroupCollection
.requires DXF R13 or later
-
layers
¶ Shortcut for
Drawing.tables.layers
Reference to the layers table, where you can create, get and remove layers, see also
Table
andLayer
-
styles
¶ Shortcut for
Drawing.tables.styles
Reference to the styles table, see also
Style
.
-
dimstyles
¶ Shortcut for
Drawing.tables.dimstyles
Reference to the dimstyles table, see also
DimStyle
.
-
linetypes
¶ Shortcut for
Drawing.tables.linetypes
Reference to the linetypes table, see also
Linetype
.
-
views
¶ Shortcut for
Drawing.tables.views
Reference to the views table, see also
View
.
-
viewports
¶ Shortcut for
Drawing.tables.viewports
Reference to the viewports table, see also
Viewport
.
-
ucs
¶ Shortcut for
Drawing.tables.ucs
Reference to the ucs table, see also
UCS
.
-
appids
¶ Shortcut for
Drawing.tables.appids
Reference to the appids table, see also
AppID
.
-
materials
¶ MaterialCollection
of allMaterial
objects.
-
mline_styles
¶ MLineStyleCollection
of allMLineStyle
objects.
-
mleader_styles
¶ MLeaderStyleCollection
of allMLeaderStyle
objects.
-
units
¶ Get and set the document/modelspace base units as enum, for more information read this: DXF Units.
-
save
(encoding: str = None, fmt: str = 'asc') → None¶ Write drawing to file-system by using the
filename
attribute as filename. Override file encoding by argument encoding, handle with care, but this option allows you to create DXF files for applications that handles file encoding different than AutoCAD.Parameters: - encoding – override default encoding as Python encoding string like
'utf-8'
- fmt –
'asc'
for ASCII DXF (default) or'bin'
for Binary DXF
- encoding – override default encoding as Python encoding string like
-
saveas
(filename: Union[str, Path], encoding: str = None, fmt: str = 'asc') → None¶ Set
Drawing
attributefilename
to filename and write drawing to the file system. Override file encoding by argument encoding, handle with care, but this option allows you to create DXF files for applications that handles file encoding different than AutoCAD.Parameters: - filename – file name as string
- encoding – override default encoding as Python encoding string like
'utf-8'
- fmt –
'asc'
for ASCII DXF (default) or'bin'
for Binary DXF
-
write
(stream: Union[TextIO, BinaryIO], fmt: str = 'asc') → None¶ Write drawing as ASCII DXF to a text stream or as Binary DXF to a binary stream. For DXF R2004 (AC1018) and prior open stream with drawing
encoding
andmode='wt'
. For DXF R2007 (AC1021) and later useencoding='utf-8'
, or better use the later addedDrawing
propertyoutput_encoding
which returns the correct encoding automatically. The correct and required error handler iserrors='dxfreplace'
!If writing to a
StringIO
stream, useDrawing.encode()
to encode the result string fromStringIO.get_value()
:binary = doc.encode(stream.get_value())
Parameters: - stream – output text stream or binary stream
- fmt –
'asc'
for ASCII DXF (default) or'bin'
for binary DXF
-
encode_base64
() → bytes¶ Returns DXF document as base64 encoded binary data.
-
encode
(s: str) → bytes¶ Encode string s with correct encoding and error handler.
-
query
(query: str = '*') → ezdxf.query.EntityQuery¶ Entity query over all layouts and blocks, excluding the OBJECTS section.
Parameters: query – query string See also
-
groupby
(dxfattrib='', key=None) → dict¶ Groups DXF entities of all layouts and blocks (excluding the OBJECTS section) by a DXF attribute or a key function.
Parameters: - dxfattrib – grouping DXF attribute like
'layer'
- key – key function, which accepts a
DXFEntity
as argument and returns a hashable grouping key orNone
to ignore this entity.
See also
groupby()
documentation- dxfattrib – grouping DXF attribute like
-
modelspace
() → ezdxf.layouts.layout.Modelspace¶ Returns the modelspace layout, displayed as
'Model'
tab in CAD applications, defined by block record named'*Model_Space'
.
-
layout
(name: str = None) → Layout¶ Returns paperspace layout name or returns first layout in tab order if name is
None
.
-
active_layout
() → Layout¶ Returns the active paperspace layout, defined by block record name
'*Paper_Space'
.
-
layout_names
() → Iterable[str]¶ Returns all layout names (modelspace
'Model'
included) in arbitrary order.
-
layout_names_in_taborder
() → Iterable[str]¶ Returns all layout names in tab order, layout “Model” (model space) is always the first name.
-
new_layout
(name, dxfattribs=None) → Layout¶ Create a new paperspace layout name. Returns a
Layout
object. DXF R12 (AC1009) supports only one paperspace layout, only the active paperspace layout is saved, other layouts are dismissed.Parameters: - name – unique layout name
- dxfattribs – additional DXF attributes for the
DXFLayout
entity
Raises: DXFValueError
–Layout
name already exist
-
delete_layout
(name: str) → None¶ Delete paper space layout name and all entities owned by this layout. Available only for DXF R2000 or later, DXF R12 supports only one paperspace and it can’t be deleted.
-
add_image_def
(filename: str, size_in_pixel: Tuple[int, int], name=None)¶ Add an image definition to the objects section.
Add an
ImageDef
entity to the drawing (objects section). filename is the image file name as relative or absolute path and size_in_pixel is the image size in pixel as (x, y) tuple. To avoid dependencies to external packages, ezdxf can not determine the image size by itself. Returns aImageDef
entity which is needed to create an image reference. name is the internal image name, if set toNone
, name is auto-generated.Absolute image paths works best for AutoCAD but not really good, you have to update external references manually in AutoCAD, which is not possible in TrueView. If the drawing units differ from 1 meter, you also have to use:
set_raster_variables()
.Parameters: - filename – image file name (absolute path works best for AutoCAD)
- size_in_pixel – image size in pixel as (x, y) tuple
- name – image name for internal use, None for using filename as name (best for AutoCAD)
See also
-
set_raster_variables
(frame: int = 0, quality: int = 1, units: str = 'm')¶ Set raster variables.
Parameters: - frame –
0
= do not show image frame;1
= show image frame - quality –
0
= draft;1
= high - units –
units for inserting images. This defines the real world unit for one drawing unit for the purpose of inserting and scaling images with an associated resolution.
mm Millimeter cm Centimeter m Meter (ezdxf default) km Kilometer in Inch ft Foot yd Yard mi Mile
- frame –
-
set_wipeout_variables
(frame=0)¶ Set wipeout variables.
Parameters: frame – 0
= do not show image frame;1
= show image frame
-
add_underlay_def
(filename: str, fmt: str = 'ext', name: str = None)¶ Add an
UnderlayDef
entity to the drawing (OBJECTS section). filename is the underlay file name as relative or absolute path and fmt as string (pdf, dwf, dgn). The underlay definition is required to create an underlay reference.Parameters: - filename – underlay file name
- fmt – file format as string
'pdf'|'dwf'|'dgn'
or'ext'
for getting file format from filename extension - name – pdf format = page number to display; dgn format =
'default'
; dwf: ????
-
add_xref_def
(filename: str, name: str, flags: int = 20)¶ Add an external reference (xref) definition to the blocks section.
Parameters: - filename – external reference filename
- name – name of the xref block
- flags – block flags
-
layouts_and_blocks
() → Iterator[GenericLayoutType]¶ Iterate over all layouts (modelspace and paperspace) and all block definitions.
-
chain_layouts_and_blocks
() → Iterator[DXFEntity]¶ Chain entity spaces of all layouts and blocks. Yields an iterator for all entities in all layouts and blocks.
-
reset_fingerprint_guid
()¶ Reset fingerprint GUID.
-
reset_version_guid
()¶ Reset version GUID.
-
set_modelspace_vport
(height, center=(0, 0), *, dxfattribs=None) → VPort¶ Set initial view/zoom location for the modelspace, this replaces the current “*Active” viewport configuration (
VPort
).Parameters: - height – modelspace area to view
- center – modelspace location to view in the center of the CAD application window.
- dxfattribs – additional DXF attributes for the VPORT entity
Changed in version 0.17.2: added argument dxfattribs to pass additional DXF attributes to the VPORT entity
-
audit
() → ezdxf.audit.Auditor¶ Checks document integrity and fixes all fixable problems, not fixable problems are stored in
Auditor.errors
.If you are messing around with internal structures, call this method before saving to be sure to export valid DXF documents, but be aware this is a long running task.
-
validate
(print_report=True) → bool¶ Simple way to run an audit process. Fixes all fixable problems, return
False
if not fixable errors occurs, to get more information about not fixable errors useaudit()
method instead.Parameters: print_report – print report to stdout Returns:
True
if no errors occurred
-
ezdxf_metadata
() → MetaData¶ Returns the ezdxf
ezdxf.document.MetaData
object, which manages ezdxf and custom metadata in DXF files. For more information see: Ezdxf Metadata.New in version 0.17.
-