raygeo.formats.dxf.reader
Reading DXF documents.
The reader never fails on a single unreadable entity: anything it could not represent is reported in
ReadOutput.issues, so a file that is partly unsupported still imports the parts that are.
DxfHeader
Details of a DXF document that are not geometry.
acad_version
acad_version: str
The drawing format marker from $ACADVER.
extents
extents: Optional[tuple[float, float, float, float]]
The declared drawing extents as (x_min, y_min, x_max, y_max), or None when the file does not
state them.
insunits
insunits: int
The $INSUNITS value, or 0 when the file states no unit.
ReadOutput
The geometry and metadata a DXF reader extracted from a document.
bounds
bounds: tuple[float, float, float, float]
Bounding rectangle of all drawn content, in native units, as (x_min, y_min, x_max, y_max).
is_y_down
is_y_down: bool
Whether the native Y axis points down. Always False for DXF.
issues
issues: list[str]
Notes about content that was skipped or approximated.
layers
layers: list[tuple[str, geo.Geometry]]
One geometry per layer, as (layer_name, geometry) pairs in document order.
max_z
max_z: float
Highest Z value the drawing spans, in native units.
min_z
min_z: float
Lowest Z value the drawing spans, in native units.
units_to_mm
units_to_mm: float
Multiplier converting native units to millimetres.
has_z_variation()
has_z_variation(tolerance: float = 0.0001) -> bool
True when the drawing spans more than one Z level.
| Parameter | Type | Description |
|---|---|---|
tolerance | float = 0.0001 | Smallest Z difference that counts as variation, in native units. |
| Returns | bool |
is_empty()
is_empty() -> bool
True when nothing drawable was found.
| Parameter | Type | Description |
|---|---|---|
| Returns | bool |
Functions
read()
read(data: str) -> formats.dxf.reader.ReadOutput
Read a DXF document into geometry.
Supports lines, arcs, circles, ellipses, polylines with bulges, splines (including NURBS) and block
insertions, which are flattened into the drawing. Content the reader cannot represent is listed in
issues rather than raising.
Raises: ValueError — When the input is not a group-code stream.
| Parameter | Type | Description |
|---|---|---|
data | str | The DXF file contents as text. |
| Returns | formats.dxf.reader.ReadOutput | Per-layer geometry in native units, Y up, with the drawing bounds, the unit conversion factor and any issues. |
| Complexity | O(n) where n = size of the document |