Document & Layout¶
Document¶
@dataclass(frozen=True)
class Document:
path: str
version: str
decode_path: str | None = None
decode_version: str | None = None
A DWG document. Created by ezdwg.read().
Properties¶
| Property | Type | Description |
|---|---|---|
path |
str |
Path to the DWG file |
version |
str |
DWG version code (e.g. "AC1015") |
decode_path |
str \| None |
Path used for decoding (defaults to path) |
decode_version |
str \| None |
Version used for decoding (defaults to version) |
Methods¶
modelspace¶
Document.modelspace() -> Layout
Return the modelspace layout.
Example:
doc = ezdwg.read("drawing.dwg")
msp = doc.modelspace()
plot¶
Document.plot(*args, **kwargs) -> Axes
Plot all entities in the modelspace. Accepts the same parameters as ezdwg.plot().
export_dxf¶
Document.export_dxf(output_path: str, **kwargs) -> ConvertResult
Export the modelspace to a DXF file. Accepts the same keyword arguments as ezdwg.to_dxf().
export_dwg¶
Document.export_dwg(output_path: str, **kwargs) -> WriteResult
Export the modelspace to a DWG file using the native writer. Accepts the same keyword arguments as ezdwg.to_dwg().
Layout¶
@dataclass(frozen=True)
class Layout:
doc: Document
name: str
A drawing layout (e.g. modelspace).
Methods¶
query¶
Layout.query(types: str | Iterable[str] | None = None) -> Iterator[Entity]
Iterate over entities, optionally filtered by type.
Parameters:
types— Space-separated type names (e.g."LINE ARC"), an iterable of type names, orNonefor all types.
Returns: Iterator of Entity objects.
Examples:
# All entities
for entity in msp.query():
print(entity.dxftype)
# Filter by type string
for line in msp.query("LINE"):
print(line.dxf["start"])
# Multiple types
for entity in msp.query("LINE ARC CIRCLE"):
print(entity.dxftype, entity.handle)
# From an iterable
for entity in msp.query(["LINE", "ARC"]):
print(entity.dxftype)
iter_entities¶
Layout.iter_entities(types: str | Iterable[str] | None = None) -> Iterator[Entity]
Alias for query().
plot¶
Layout.plot(*args, **kwargs) -> Axes
Plot entities in this layout. Accepts the same parameters as ezdwg.plot().
export_dxf¶
Layout.export_dxf(output_path: str, **kwargs) -> ConvertResult
Export this layout to a DXF file. Accepts the same keyword arguments as ezdwg.to_dxf().
export_dwg¶
Layout.export_dwg(output_path: str, **kwargs) -> WriteResult
Export this layout to a DWG file using the native writer. Accepts the same keyword arguments as ezdwg.to_dwg().