This module provide tools for the recursive decomposition of nested block
reference structures into a flat stream of DXF entities and converting DXF
entities into geometric primitives of
MeshBuilder objects encapsulated into
Do not expect advanced vectorization capabilities: Text entities like TEXT,
ATTRIB, ATTDEF and MTEXT get only a rough border box representation.
text2path add-on can convert text into paths.
VIEWPORT, IMAGE and WIPEOUT are represented by their clipping path.
Unsupported entities: all ACIS based entities, XREF, UNDERLAY, ACAD_TABLE,
RAY, XLINE. Unsupported entities will be ignored.
Text Boundary Calculation¶
Text boundary calculations are based on monospaced (fixed-pitch, fixed-width, non-proportional) font metrics, which do not provide a good accuracy for text height calculation and much less accuracy for text width calculation. It is possible to improve this results by using the font support from the optional Matplotlib package.
Install Matplotlib from command line:
C:\> pip3 install matplotlib
The Matplotlib font support will improve the results for TEXT, ATTRIB and ATTDEF. The MTEXT entity has many advanced features which would require a full “Rich Text Format” rendering and that is far beyond the goals and capabilities of this library, therefore the boundary box for MTEXT will never be as accurate as in a dedicated CAD application.
Using the Matplotlib font support adds runtime overhead, therefore it is possible to deactivate the Matplotlib font support by setting the global option:
options.use_matplotlib_font_support = False
Flatten Complex DXF Entities¶
recursive_decompose(entities: Iterable[ezdxf.entities.dxfentity.DXFEntity]) → Iterable[ezdxf.entities.dxfentity.DXFEntity]¶
Recursive decomposition of the given DXF entity collection into a flat stream of DXF entities. All block references (INSERT) and entities which provide a
virtual_entities()method will be disassembled into simple DXF sub-entities, therefore the returned entity stream does not contain any INSERT entity.
Point entities will not be disassembled into DXF sub-entities, as defined by the current point style $PDMODE.
These entity types include sub-entities and will be decomposed into simple DXF entities:
Decomposition of XREF, UNDERLAY and ACAD_TABLE entities is not supported.
These functions disassemble DXF entities into simple geometric objects
like meshes, paths or vertices. The
Primitive is a simplified
intermediate class to use a common interface on various DXF entities.
make_primitive(entity: ezdxf.entities.dxfentity.DXFEntity, max_flattening_distance=None) → ezdxf.disassemble.Primitive¶
Factory to create path/mesh primitives. The max_flattening_distance defines the max distance between the approximation line and the original curve. Use max_flattening_distance to override the default value.
Returns an empty primitive for unsupported entities. The empty state of a primitive can be checked by the property
meshattributes of an empty primitive are
vertices()method yields no vertices.
to_primitives(entities: Iterable[ezdxf.entities.dxfentity.DXFEntity], max_flattening_distance: Optional[float] = None) → Iterable[ezdxf.disassemble.Primitive]¶
Yields all DXF entities as path or mesh primitives. Yields unsupported entities as empty primitives, see
- entities – iterable of DXF entities
- max_flattening_distance – override the default value
to_meshes(primitives: Iterable[ezdxf.disassemble.Primitive]) → Iterable[ezdxf.render.mesh.MeshBuilder]¶
MeshBuilderobjects from the given primitives. Ignores primitives without a defined mesh.
to_paths(primitives: Iterable[ezdxf.disassemble.Primitive]) → Iterable[ezdxf.path.path.Path]¶
Pathobjects from the given primitives. Ignores primitives without a defined path.
to_vertices(primitives: Iterable[ezdxf.disassemble.Primitive]) → Iterable[ezdxf.math._vector.Vec3]¶
Yields all vertices from the given primitives. Paths will be flattened to create the associated vertices. See also
to_control_vertices()to collect only the control vertices from the paths without flattening.
to_control_vertices(primitives: Iterable[ezdxf.disassemble.Primitive]) → Iterable[ezdxf.math._vector.Vec3]¶
Yields all path control vertices and all mesh vertices from the given primitives. Like
to_vertices(), but without flattening.
Interface class for path/mesh primitives.
Reference to the source DXF entity of this primitive.
The max_flattening_distance attribute defines the max distance in drawing units between the approximation line and the original curve. Set the value by direct attribute access. (float) default = 0.01
vertices() → Iterable[ezdxf.math._vector.Vec3]¶
Yields all vertices of the path/mesh representation as
bbox(fast=False) → ezdxf.math.bbox.BoundingBox¶
BoundingBoxof the path/mesh representation. Returns the precise bounding box for the path representation if fast is
False, otherwise the bounding box for Bézier curves is based on their control points.