The indention of the recover module is to provide a more stable and reliable DXF loading function. This is required because the DXF reference is often not precise about valid data ranges or does not show the correct usage of DXF attributes and structures and therefore exist many DXF files with structural flaws.
The recover.read()
and recover.readfile()
functions will repair as much
flaws as possible and run the required audit process automatically
afterwards and return the result of this audit process:
import sys
import ezdxf
from ezdxf import recover
try:
doc, auditor = recover.readfile("messy.dxf")
except IOError:
print(f'Not a DXF file or a generic I/O error.')
sys.exit(1)
except ezdxf.DXFStructureError:
print(f'Invalid or corrupted DXF file.')
sys.exit(2)
if auditor.has_errors:
auditor.print_error_report()
A recovered DXF file can still have unrecoverable errors, but this is just a problem when saving the recovered DXF file.
This extra work requires additional efforts and longer loading times,
to avoid this penalty for DXF files from trusted sources like AutoCAD or
BricsCAD, the current loading function ezdxf.readfile()
remains as it was,
except the legacy_mode
argument was removed to force usage of the recover
module.
Support for the start- and end width attributes of LWPOLYLINE and 2D POLYLINE vertices to draw banded 2D lines.
A simple qsave()
function to export renderings of DXF layouts as raster- or
vector graphic by matplotlib
:
import ezdxf
from ezdxf.addons.drawing import matplotlib
doc = ezdxf.readfile('your.dxf')
matplotlib.qsave(doc.modelspace(), 'your.png')
Further Improvements:
matplotlib
back-end got line-weight (width) support.Path()
tool as basic rendering tool.Arc()
got support for using ConstructionArc()
as construction tool.Leader()
got methods virtual_entities()
and explode()
as render support
tools.LWPolyline.has_width
property is True
if any width attribute is set.Polyline.has_width
property is True
if any width attribute is set.Polyline.audit()
for extended verify and repair support.Insert.explode()
got support for MINSERT (multi insert).Insert.virtual_entities()
got support for MINSERT (multi insert).Insert.mcount
property returns multi insert count.Insert.multi_insert()
yields a virtual INSERT entity for each grid
element of a MINSERT entity.Polyline.append_formatted_vertices()
with support for user defined
point format like LWPOLYLINE.DXFVertex.format()
method to support user defined point format like
LWPOLYLINE.Image.boundary_path_wcs()
method returns the clipping boundary path in
WCS coordinates.Wipeout.boundary_path_wcs()
method returns the clipping boundary path
in WCS coordinates.Wipeout.set_masking_area()
method set the masking area (clipping
boundary path) from WCS coordinates.Layout.add_wipeout()
factory function to create WIPEOUT entities.DXFEntity.new_extension_dict()
to create explicit a new extension
dictionary.TraceBuilder()
class to create banded 2D lines and curves by quadrilaterals,
see docs.
Path()
class to create complex paths only by lines and cubic Bèzier curves.
Supports splines, circular- and elliptic arcs as path elements all approximated
by cubic Bèzier curves, see docs.
Tools to reorder DXF entities by handle or a special sort handle mapping, see docs.
BSpline.is_clamped
property is True
for a clamped (open) B-spline.Bezier()
and Bezier4p()
classes got methods to revers and transform curves.arc_segment_count()
tool function to calculate the required segment count for
an arc approximation defined by a maximum sagitta value.UCS()
got a transform()
method as general transformation interface.New errors
argument for all DXF loading functions like ezdxf.readfile()
to support different methods for unicode error handling:
UnicodeDecodeError()
exception for invalid dataThe ezdxf.has_dxf_unicode(s)
and ezdxf.decode_dxf_unicode(s)
are new support
functions to decode unicode characters "\U+xxxx" manually,
see docs.
The decoding of unicode characters "\U+xxxx" is not done automatically by the
regular loading functions like ezdxf.readfile()
to avoid a speed penalty,
only the recover
module does the decoding automatically, because this loading
mode is already slow.
This kind of encoding is most likely used only in older DXF versions, because
since DXF R2007 the whole DXF file is encoded in utf8
and a special unicode
encoding is not necessary.
New Drawing.encode(s)
function to encode unicode strings with correct encoding
and error handler.
self.drawing
Auditor()
creates a place holder object as default
value.ValueError()
exceptions, please report this table
names (layers, linetypes, styles, ...). DXF unicode notation "\U+xxxx" raises
a ValueError()
if used as resource names like layer name or text style names,
such files can only be loaded by the new recover
module.ezdxf.recover
module to load DXF Documents with structural flaws, see
docsrecover
module for more information.addons.drawing.Frontend()
supports width attributes of LWPOLYLINE and
2D POLYLINE entitiesTraceBuilder()
a render tool to generate quadrilaterals (TRACE, SOLID
or 3DFACE), from LWPOLYLINE or 2D POLYLINE with width information,
see docsPath()
a render tool for paths build of lines and cubic Bèzier curves,
used for faster rendering of LWPOLYLINE, POLYLINE and SPLINE entities for
render back-ends, see docsdrawing.matplotlib.qsave()
function, a simplified matplotlib export interfaceArc.construction_tool()
returns the 2D ConstructionArc()
Arc.apply_construction_tool()
apply parameters from ConstructionArc()
Leader.virtual_entities()
yields 'virtual' DXF primitivesLeader.explode()
explode LEADER as DXF primitives into target layoutLWPolyline.has_width
property is True
if any width attribute is setPolyline.has_width
property is True
if any width attribute is setPolyline.audit()
extended verify and repair supportPolyline.append_formatted_vertices()
, support for user defined point formatDXFVertex.format()
support for user defined point format Drawing.blocks.purge()
delete all unused blocks but protect modelspace-
and paperspace layouts, special arrow blocks and DIMENSION and ACAD_TABLE
blocks in use, but see also warning in the
docsInsert.explode()
support for MINSERT (multi insert)Insert.virtual_entities()
support for MINSERT (multi insert)Insert.mcount
property returns multi insert countInsert.multi_insert()
yields a virtual INSERT entity for each grid
element of a MINSERT entityLayout.add_wipeout()
interface to create WIPEOUT entitiesImage.boundary_path_wcs()
, returns boundary path in WCS coordinatesWipeout.boundary_path_wcs()
, returns boundary path in WCS coordinatesWipeout.set_masking_area()
BSpline.is_clamped
property is True
for a clamped (open) B-splineUCS.transform()
general transformation interfaceBezier4P.transform()
general transformation interfaceBezier4P.reverse()
returns object with reversed control point orderBezier.transform()
general transformation interfaceBezier.reverse()
returns object with reversed control point orderhas_clockwise_orientation(vertices)
returns True
if the closed
polygon of 2D vertices has clockwise orientationDXFEntity.new_extension_dict()
, create explicit a new extension dictionaryezdxf.reorder
, support module to implement modified entities redraw orderEZDXF_TEST_FILES
,
imported automatically as ezdxf.EZDXF_TEST_FILES
arc_chord_length()
and arc_segment_count()
tool functions in
ezdxf.math
Drawing.encode()
to encode unicode strings with correct encoding and
error handlerezdxf.has_dxf_unicode()
to detect "\U+xxxx" encoded charsezdxf.decode_dxf_unicode()
to decode strings containingrecover
module decodes such strings
automatically.DXFEntity.get_extension_dict()
, raises AttributeError
if entity
has no extension dictionary DXFEntity.has_extension_dict
is now a property not a methodlinspace()
uses Decimal()
for precise calculations, but still
returns an iterable of float
Drawing.blocks.delete_all_blocks()
, unsafe mode is disabled and
argument safe
is deprecated, will be removed in v0.16DXFValueError
for adding invalid handlesBaseLayout.add_entity()
will bind entity automatically to doc/db if possibleModel == MODEL
option.check_entity_tag_structure
, entity check is done only in
recover modelegacy_mode
in ezdxf.read()
and ezdxf.readfile()
, use the
ezdxf.recover
module to load DXF Documents with structural flawsDXFEntity.drawing
use DXFEntity.doc
DXFEntity.entitydb
DXFEntity.dxffactory
DXFInvalidLayerName
, replaced by DXFValueError
Image.get_boundary_path()
, replaced by property Image.boundary_path
Image.get_image_def()
, replaced by property Image.image_def
filter_stack
argument in ezdxf.read()
and ezdxf.readfile()
non-constant-attribs
flag (2) in BLOCK at DXF export if non
constant ATTDEF entities are present.HATCH
extrusion vector (210) is mandatory?