New in version 0.16.
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
Hatch entity is special because this entity can
not be reduced into as single geometric primitive. The
function returns an empty primitive, instead use the
function to convert a
Hatch entity into multiple
(boundary path) primitives:
primitives = list(to_primitives([hatch_entity]))
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 font support from the Matplotlib package, but this is an optional feature and has to be activated explicit:
from ezdxf import options options.use_matplotlib_font_support = True
This is a global option for the current running Interpreter and it is active until deactivated:
options.use_matplotlib_font_support = False
This feature requires a working Matplotlib installation else an
exception will be raised sooner or later. This feature also depends on the
drawing add-on, which is installed by default. Using
the Matplotlib font support adds runtime overhead at the first
usage of any of the text related primitives.
Global option to set the font caching directory:
Install Matplotlib from command line:
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.
Flatten Complex DXF Entities¶
recursive_decompose(entities: Iterable[DXFEntity]) → Iterable[DXFEntity]¶
Recursive decomposition of the given DXF entity collection into a flat DXF entity stream. 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: DXFEntity, max_flattening_distance=None) → 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.
primitives = list(to_primitives([hatch_entity]))
to_primitives(entities: Iterable[DXFEntity], max_flattening_distance: float = None) → Iterable[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[Primitive]) → Iterable[MeshBuilder]¶
MeshBuilderobjects from the given primitives. Ignores primitives without a defined mesh.
to_paths(primitives: Iterable[Primitive]) → Iterable[Path]¶
Pathobjects from the given primitives. Ignores primitives without a defined path.
to_vertices(primitives: Iterable[Primitive]) → Iterable[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[Primitive]) → Iterable[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
None, idiom to check if is a path representation (could be empty):
if primitive.path is not None: process(primitive.path)
None, idiom to check if is a mesh representation (could be empty):
if primitive.mesh is not None: process(primitive.mesh)
Returns True if represents an empty primitive which do not yield any vertices.