### Install ezdwg with Both Optional Dependencies Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/installation.md Install ezdwg with both plotting and DWG to DXF conversion dependencies. ```bash pip install "ezdwg[plot,dxf]" ``` -------------------------------- ### Install ezdwg Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Install the ezdwg library from PyPI. Use the optional dependencies for plotting or DXF conversion. ```bash pip install ezdwg ``` ```bash pip install "ezdwg[plot]" ``` ```bash pip install "ezdwg[dxf]" ``` -------------------------------- ### Install ezdwg from Source Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/installation.md Build and install ezdwg from its source code repository. Requires a Rust toolchain and Python 3.10+. ```bash git clone https://github.com/monozukuri-ai/ezdwg.git cd ezdwg maturin develop pip install -e . ``` -------------------------------- ### Install ezdwg from PyPI Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/installation.md Use this command to install the base ezdwg package from the Python Package Index. ```bash pip install ezdwg ``` -------------------------------- ### Install ezdwg with DXF Conversion Dependencies Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/installation.md Install ezdwg with optional dependencies for DWG to DXF conversion using the ezdxf backend. ```bash pip install "ezdwg[dxf]" ``` -------------------------------- ### Check ezdwg Version Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/cli.md Displays the installed version of the ezdwg CLI. This is a basic command to verify installation. ```bash ezdwg --version ``` -------------------------------- ### Install ezdwg with Plotting Dependencies Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/installation.md Install ezdwg along with optional plotting dependencies, which require matplotlib. ```bash pip install "ezdwg[plot]" ``` -------------------------------- ### Convert DWG to DXF File Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Converts a DWG file to a DXF file. Requires the 'dxf' extra to be installed. ```python import ezdwg result = ezdwg.to_dxf("input.dwg", "output.dxf") print(f"Written: {result.written_entities}/{result.total_entities} entities") ``` -------------------------------- ### Quick Start: Read DWG and Query Entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Read a DWG file and iterate through its entities, printing their type, handle, and DXF data. Supports various entity types. ```python import ezdwg doc = ezdwg.read("path/to/file.dwg") msp = doc.modelspace() for e in msp.query("LINE LWPOLYLINE ARC CIRCLE ELLIPSE POINT TEXT MTEXT DIMENSION"): print(e.dxftype, e.handle, e.dxf) ``` -------------------------------- ### EZDWG Usage Example: Version Detection and Entity Decoding Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Demonstrates basic usage of the EZDWG library, including detecting the DWG file version and iterating through decoded line and arc entities. Note that arc angles are returned in radians. ```python from ezdwg import raw # Detect version version = raw.detect_version("drawing.dwg") print(f"Version: {version}") # Decode lines for handle, sx, sy, sz, ex, ey, ez in raw.decode_line_entities("drawing.dwg"): print(f"Line {handle}: ({sx},{sy},{sz}) -> ({ex},{ey},{ez})") # Decode arcs (angles in radians!) import math for handle, cx, cy, cz, r, sa, ea in raw.decode_arc_entities("drawing.dwg"): print(f"Arc {handle}: center=({cx},{cy},{cz}) r={r} " f"angles={math.degrees(sa):.1f}°-{math.degrees(ea):.1f}°") ``` -------------------------------- ### Plot DWG Document to Display Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Plots the content of a DWG document to the default display. Requires the 'plot' extra to be installed. ```python import ezdwg doc = ezdwg.read("path/to/file.dwg") doc.plot() ``` -------------------------------- ### Access Modelspace Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/reading-files.md Get the modelspace from the Document object to access drawing entities. This returns a Layout object. ```python msp = doc.modelspace() ``` -------------------------------- ### Filter Entities by Type (Lines) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Specifically queries and iterates over LINE entities, printing their start and end points. ```python # Only lines for line in msp.query("LINE"): print(line.dxf["start"], "->", line.dxf["end"]) ``` -------------------------------- ### Decode Line Entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Decodes line entities from a DWG file, returning tuples with handle and coordinates for start and end points. ```python raw.decode_line_entities(path: str, limit: int | None = None) -> list[tuple[int, float, float, float, float, float, float]] ``` -------------------------------- ### Plot Specific Entity Types Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/plotting.md Filter and plot only specific types of entities from a DWG document. This example shows plotting only lines and arcs, and then only text entities. ```python # Only lines and arcs doc.plot(types="LINE ARC") # Only text entities doc.plot(types="TEXT MTEXT") ``` -------------------------------- ### Decode Arc Entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Decodes arc entities from a DWG file, returning tuples with handle, center coordinates, radius, start angle, and end angle. Angles are in radians. ```python raw.decode_arc_entities(path: str, limit: int | None = None) -> list[tuple[int, float, float, float, float, float, float]] ``` -------------------------------- ### raw.decode_line_entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Decodes line entities from a DWG file, returning handle, start and end coordinates, with an optional limit. ```APIDOC ## raw.decode_line_entities ### Description Decode line entities. Each tuple: `(handle, start_x, start_y, start_z, end_x, end_y, end_z)`. ### Method GET ### Endpoint /raw/decode_line_entities ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. - **limit** (int | None) - Optional - The maximum number of line entities to decode. ### Response #### Success Response (200) - **lines** (list[tuple[int, float, float, float, float, float, float]]) - A list of tuples, each containing the entity handle and its start and end coordinates. ``` -------------------------------- ### CLI: Write DWG (Native AC1015) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Use the CLI to write a DWG file with the native AC1015 writer. Specify output path, entity types, and DWG version. ```bash uvx ezdwg write examples/data/line_2000.dwg /tmp/line_2000_out.dwg --types "LINE" --dwg-version AC1015 ``` -------------------------------- ### Converting Entities to Points Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/entities.md Demonstrates the `to_points()` method for extracting key coordinates from various entity types like LINE, LWPOLYLINE, and POINT. This is useful for geometric analysis. ```python for entity in msp.query("LINE LWPOLYLINE POINT"): points = entity.to_points() print(entity.dxftype, points) ``` -------------------------------- ### CLI: Inspect DWG File Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Use the ezdwg CLI to inspect a DWG file. The --verbose flag provides more detailed output. ```bash uvx ezdwg inspect examples/data/line_2000.dwg ``` ```bash uvx ezdwg inspect examples/data/line_2000.dwg --verbose ``` -------------------------------- ### Querying Entities by Multiple Types Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/entities.md Illustrates how to query for multiple entity types simultaneously using a space-separated string. This is efficient for processing related entity types. ```python msp = doc.modelspace() # Multiple types (space-separated) for entity in msp.query("LINE ARC CIRCLE"): print(entity.dxftype, entity.dxf) ``` -------------------------------- ### CLI: Convert DWG to DXF Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Convert a DWG file to DXF format using the CLI. Specify output path, entity types, and DXF version. ```bash uvx --from "ezdwg[dxf]" ezdwg convert examples/data/line_2000.dwg /tmp/line_2000_out.dxf ``` ```bash uvx --from "ezdwg[dxf]" ezdwg convert examples/data/arc_2000.dwg /tmp/arc_2000_out.dxf --types "ARC" --dxf-version R2010 ``` -------------------------------- ### Convert DWG to DXF from File Path Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/convert.md Perform a basic conversion of a DWG file to DXF format using its file path. Shows the number of entities written and total entities processed. ```python import ezdwg result = ezdwg.to_dxf("input.dwg", "output.dxf") print(f"Written: {result.written_entities}/{result.total_entities}") ``` -------------------------------- ### decode_ellipse_entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Decodes ELLIPSE entities from a DWG file. Each decoded entity is returned as a tuple containing its handle, center, extrusion, major axis, ratio, start angle, and end angle. ```APIDOC ## decode_ellipse_entities ### Description Decodes ELLIPSE entities from a DWG file. Each decoded entity is returned as a tuple containing its handle, center, extrusion, major axis, ratio, start angle, and end angle. ### Method ```python raw.decode_ellipse_entities(path: str, limit: int | None = None) -> list[tuple[int, ...]] ``` ### Parameters * **path** (str) - Required - The path to the DWG file. * **limit** (int | None) - Optional - The maximum number of entities to decode. ### Response * **list[tuple[int, ...]]** - A list of tuples, where each tuple represents an ELLIPSE entity with its handle, center, extrusion, major_axis, ratio, start_angle, and end_angle. ``` -------------------------------- ### Inspect DWG File Information Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/cli.md Shows basic information about a DWG file, including path, DWG version, decode version, and entity counts. Use the --verbose flag for expanded diagnostics. ```bash ezdwg inspect path/to/file.dwg ``` ```bash ezdwg inspect path/to/file.dwg --verbose ``` -------------------------------- ### Decode Ellipse Entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Decodes ellipse entities from a DWG file. The returned tuple includes the handle, center, extrusion vector, major axis, ratio, start angle, and end angle. ```python raw.decode_ellipse_entities(path: str, limit: int | None = None) -> list[tuple[int, ...]] ``` -------------------------------- ### Querying All Entities in Modelspace Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/entities.md Shows how to retrieve all supported entity types from the modelspace of a DXF document. This is useful for iterating through all drawing objects. ```python msp = doc.modelspace() # All supported entity types for entity in msp.query(): print(entity.dxftype, entity.handle) ``` -------------------------------- ### Layout Methods Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Provides methods for querying entities within a layout, plotting, and exporting the layout to DXF or DWG formats. ```APIDOC ## Layout.query ### Description Iterate over entities, optionally filtered by type. ### Method ```python Layout.query(types: str | Iterable[str] | None = None) -> Iterator[Entity] ``` ### Parameters #### Query Parameters - **types** (str | Iterable[str] | None) - Space-separated type names (e.g. "LINE ARC"), an iterable of type names, or `None` for all types. ### Returns Iterator of [`Entity`](entity.md) objects. ### Examples ```python # 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) ``` ``` ```APIDOC ## Layout.iter_entities ### Description Alias for `query()`. ### Method ```python Layout.iter_entities(types: str | Iterable[str] | None = None) -> Iterator[Entity] ``` ``` ```APIDOC ## Layout.plot ### Description Plot entities in this layout. ### Method ```python Layout.plot(*args, **kwargs) -> Axes ``` ### Notes Accepts the same parameters as [`ezdwg.plot()`](core.md#ezdwgplot). ``` ```APIDOC ## Layout.export_dxf ### Description Export this layout to a DXF file. ### Method ```python Layout.export_dxf(output_path: str, **kwargs) -> ConvertResult ``` ### Notes Accepts the same keyword arguments as [`ezdwg.to_dxf()`](core.md#ezdwgto_dxf). ``` ```APIDOC ## Layout.export_dwg ### Description Export this layout to a DWG file using the native writer. ### Method ```python Layout.export_dwg(output_path: str, **kwargs) -> WriteResult ``` ### Notes Accepts the same keyword arguments as [`ezdwg.to_dwg()`](core.md#ezdwgto_dwg). ``` -------------------------------- ### Read a DWG File Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Opens a DWG file and retrieves its version and model space. ```python import ezdwg doc = ezdwg.read("path/to/file.dwg") print(f"Version: {doc.version}") msp = doc.modelspace() ``` -------------------------------- ### Read DWG Document Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/core.md Opens a DWG file and returns a Document object. Raises ValueError for unsupported DWG versions. ```python import ezdwg doc = ezdwg.read("drawing.dwg") print(doc.version) ``` -------------------------------- ### List Object Headers Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists object headers, returning tuples of handle, offset, size, and type code. An optional limit can be applied. ```python raw.list_object_headers(path: str, limit: int | None = None) -> list[tuple[int, int, int, int]] ``` -------------------------------- ### Query Entities in Layout (All Types) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Iterates over all entities within a layout. Useful for general inspection or when no specific filtering is needed. ```python # All entities for entity in msp.query(): print(entity.dxftype) ``` -------------------------------- ### Entity Structure and Attributes Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/entities.md Demonstrates the basic structure of an ezdwg Entity object, including its type, handle, and DXF attributes dictionary. This is fundamental for understanding entity data. ```python from ezdwg import Entity # Entity fields: entity.dxftype # str — entity type name (e.g. "LINE", "ARC") entity.handle # int — unique handle within the file entity.dxf # dict[str, Any] — entity-specific attributes ``` -------------------------------- ### ezdwg CLI: Convert DWG to DXF Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Converts a DWG file to a DXF file using the ezdwg command-line tool. ```bash # Convert DWG to DXF ezdwg convert input.dwg output.dxf ``` -------------------------------- ### Read DWG and Query Entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/index.md This snippet demonstrates how to read a DWG file and query for specific entity types like LINE, ARC, and CIRCLE from the model space. It then iterates through the found entities and prints their type, handle, and DXF attributes. ```python import ezdwg doc = ezdwg.read("drawing.dwg") msp = doc.modelspace() for entity in msp.query("LINE ARC CIRCLE"): print(entity.dxftype, entity.handle, entity.dxf) ``` -------------------------------- ### Convert DWG to DXF from Layout Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/convert.md Export a specific layout from a DWG document to DXF format. ```python doc = ezdwg.read("input.dwg") msp = doc.modelspace() result = msp.export_dxf("output.dxf") ``` -------------------------------- ### Export Opened DWG Document to DXF Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Exports an already opened DWG document to a DXF file. Requires the 'dxf' extra. ```python doc = ezdwg.read("input.dwg") doc.export_dxf("output.dxf") ``` -------------------------------- ### Raw API Functions Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/index.md Offers low-level access to Rust decode functions for performance-critical operations. ```APIDOC ## Raw API Functions ### Description Offers low-level access to Rust decode functions for performance-critical operations. Returns data as tuples. ### Module - **ezdwg.raw**: Contains low-level decode functions. ### Parameters Refer to the [Raw API](raw.md) documentation for detailed information on the available functions and their return types. ``` -------------------------------- ### ezdwg CLI: Inspect DWG File Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Inspects a DWG file using the ezdwg command-line tool. ```bash # Inspect a DWG file ezdwg inspect path/to/file.dwg ``` -------------------------------- ### ezdwg.read Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/core.md Opens a DWG file and returns a Document object for further processing. Supports various DWG versions and raises ValueError for unsupported versions. ```APIDOC ## ezdwg.read ### Description Open a DWG file and return a `Document`. ### Parameters - `path` (str) - Required - Path to the DWG file. ### Returns - `Document` - A [`Document`](document.md) object. ### Raises - `ValueError` - if the DWG version is unsupported. ### Example ```python import ezdwg doc = ezdwg.read("drawing.dwg") print(doc.version) ``` ``` -------------------------------- ### Access Document Properties Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/reading-files.md Retrieve the DWG version, decoded version, and file path from the Document object. ```python doc = ezdwg.read("path/to/file.dwg") print(doc.version) # e.g. "AC1015" print(doc.decode_version) # e.g. "AC1015" print(doc.path) # file path ``` -------------------------------- ### ezdwg CLI: Write DWG (AC1015) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Writes a DWG file using the native AC1015 writer via the ezdwg command-line tool. ```bash # Write DWG (native AC1015 writer) ezdwg write input.dwg output.dwg --dwg-version AC1015 ``` -------------------------------- ### Plot DWG Document to Image File Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Plots a DWG document and saves the output to a PNG image file. Requires the 'plot' extra. ```python import matplotlib.pyplot as plt doc = ezdwg.read("path/to/file.dwg") ax = doc.plot(show=False) plt.savefig("output.png", dpi=150, bbox_inches="tight") ``` -------------------------------- ### Plot DWG Document Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/plotting.md Read a DWG file and plot its contents using the default settings. ```python import ezdwg doc = ezdwg.read("drawing.dwg") doc.plot() ``` -------------------------------- ### List Object Map Entries Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists object map entries, returning tuples of handle and offset. An optional limit can be applied. ```python raw.list_object_map_entries(path: str, limit: int | None = None) -> list[tuple[int, int]] ``` -------------------------------- ### Iterate Over All Entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Iterates through all specified entity types in the model space and prints their type, handle, and DXF data. ```python for entity in msp.query("LINE LWPOLYLINE ARC CIRCLE ELLIPSE POINT TEXT MTEXT DIMENSION"): print(entity.dxftype, entity.handle, entity.dxf) ``` -------------------------------- ### Plot Modelspace Layout Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/plotting.md Access the modelspace of a DWG document and plot its contents. ```python msp = doc.modelspace() msp.plot() ``` -------------------------------- ### Using iter_entities Alias Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/entities.md Shows the usage of `iter_entities()` as an alias for `query()`, demonstrating how to iterate and access DXF attributes for a specific entity type. ```python msp = doc.modelspace() for entity in msp.iter_entities("LINE"): print(entity.dxf) ``` -------------------------------- ### Specify DXF Version for Conversion Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/convert.md Convert a DWG file to DXF format, specifying the DXF version (e.g., R2010). Supported versions include R2000, R2004, R2007, R2010, R2013, R2018. ```python result = ezdwg.to_dxf( "input.dwg", "output.dxf", dxf_version="R2010", # default ) ``` -------------------------------- ### Export DWG from Opened Document (Native AC1015) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Export an already opened DWG document to a new DWG file using the native AC1015 writer. Specify the target DWG version. ```python doc = ezdwg.read("examples/data/line_2000.dwg") doc.export_dwg("/tmp/line_2000_rewrite.dwg", version="AC1015") ``` -------------------------------- ### Querying Entities by Single Type Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/entities.md Demonstrates filtering entities by a specific type name, such as 'LINE'. This allows targeted processing of particular entity types. ```python msp = doc.modelspace() # Filter by type name(s) for entity in msp.query("LINE"): print(entity.dxf) ``` -------------------------------- ### Access Modelspace Layout Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Retrieves the modelspace layout from a Document object. This is the primary space for drawing entities. ```python doc = ezdwg.read("drawing.dwg") msp = doc.modelspace() ``` -------------------------------- ### Document Methods Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Provides access to document-level operations such as retrieving the modelspace, analyzing the document graph, plotting, and exporting. ```APIDOC ## Document.modelspace() ### Description Return the modelspace layout. ### Method ```python Document.modelspace() -> Layout ``` ### Example ```python doc = ezdwg.read("drawing.dwg") msp = doc.modelspace() ``` ``` ```APIDOC ## Document.graph ### Description Return the graph-oriented IR for the document. The graph contains object nodes, common entity data, object edges, layer table rows, block header rows, and inferred model/paper space header handles. ### Method ```python Document.graph(limit: int | None = None) -> DocumentGraph ``` ``` ```APIDOC ## Document.plot ### Description Plot all entities in the modelspace. ### Method ```python Document.plot(*args, **kwargs) -> Axes ``` ### Notes Accepts the same parameters as [`ezdwg.plot()`](core.md#ezdwgplot). ``` ```APIDOC ## Document.export_dxf ### Description Export the modelspace to a DXF file. ### Method ```python Document.export_dxf(output_path: str, **kwargs) -> ConvertResult ``` ### Notes Accepts the same keyword arguments as [`ezdwg.to_dxf()`](core.md#ezdwgto_dxf). ``` ```APIDOC ## Document.export_dwg ### Description Export the modelspace to a DWG file using the native writer. ### Method ```python Document.export_dwg(output_path: str, **kwargs) -> WriteResult ``` ### Notes Accepts the same keyword arguments as [`ezdwg.to_dwg()`](core.md#ezdwgto_dwg). ``` -------------------------------- ### Core Functions Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/index.md Provides essential functions for reading, plotting, and converting DWG files. ```APIDOC ## Core Functions ### Description Provides essential functions for reading, plotting, and converting DWG files. ### Functions - **ezdwg.read()**: Reads a DWG file. - **ezdwg.plot()**: Plots a DWG file. - **ezdwg.to_dxf()**: Converts a DWG file to DXF format. - **ezdwg.to_dwg()**: Converts a file to DWG format. ### Parameters Refer to the [Core Functions](core.md) documentation for detailed parameter information for each function. ``` -------------------------------- ### raw.list_object_headers Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists object headers (handle, offset, size, type_code) for a DWG file, with an optional limit. ```APIDOC ## raw.list_object_headers ### Description List object headers. Each tuple: `(handle, offset, size, type_code)`. ### Method GET ### Endpoint /raw/list_object_headers ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. - **limit** (int | None) - Optional - The maximum number of headers to return. ### Response #### Success Response (200) - **headers** (list[tuple[int, int, int, int]]) - A list of tuples, where each tuple contains the object handle, offset, size, and type code. ``` -------------------------------- ### Convert DWG to DXF from Document Object Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/convert.md Convert a DWG document to DXF format after reading it into a document object. ```python doc = ezdwg.read("input.dwg") result = doc.export_dxf("output.dxf") ``` -------------------------------- ### DWG to DXF Conversion Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Convert a DWG file to DXF format programmatically. Supports specifying entity types and DXF version. ```python import ezdwg result = ezdwg.to_dxf( "examples/data/line_2000.dwg", "/tmp/line_2000_out.dxf", types="LINE ARC LWPOLYLINE", dxf_version="R2010", ) print(result) ``` -------------------------------- ### List Object Headers with Type Names Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists object headers along with their resolved type names and type classes (Entity or Object). An optional limit can be applied. ```python raw.list_object_headers_with_type(path: str, limit: int | None = None) -> list[tuple[int, int, int, int, str, str]] ``` -------------------------------- ### raw.list_object_headers_with_type Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists object headers with resolved type names and classes for a DWG file, with an optional limit. ```APIDOC ## raw.list_object_headers_with_type ### Description List object headers with resolved type names. Each tuple: `(handle, offset, size, type_code, type_name, type_class)`. `type_class` is "E" for entities and "O" for objects. ### Method GET ### Endpoint /raw/list_object_headers_with_type ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. - **limit** (int | None) - Optional - The maximum number of headers to return. ### Response #### Success Response (200) - **headers** (list[tuple[int, int, int, int, str, str]]) - A list of tuples containing handle, offset, size, type code, type name, and type class. ``` -------------------------------- ### Export Opened DWG Document to DWG (AC1015) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Exports an already opened DWG document to a DWG file using the native AC1015 writer. ```python doc = ezdwg.read("input.dwg") doc.export_dwg("output.dwg", version="AC1015") ``` -------------------------------- ### raw.detect_version Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Detects the DWG version string of a given file path. ```APIDOC ## raw.detect_version ### Description Detect the DWG version string (e.g. "AC1015"). ### Method GET ### Endpoint /raw/detect_version ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. ### Response #### Success Response (200) - **version** (str) - The detected DWG version string. ``` -------------------------------- ### Document & Layout Classes Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/index.md Enables manipulation and access to Document and Layout objects within a DWG file. ```APIDOC ## Document & Layout Classes ### Description Enables manipulation and access to Document and Layout objects within a DWG file. ### Classes - **Document**: Represents a DWG document. - **Layout**: Represents a layout within a DWG document. ### Parameters Refer to the [Document & Layout](document.md) documentation for detailed information on the properties and methods of these classes. ``` -------------------------------- ### raw.list_object_map_entries Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists object map entries (handle and offset) for a DWG file, with an optional limit. ```APIDOC ## raw.list_object_map_entries ### Description List object map entries. Each tuple: `(handle, offset)`. ### Method GET ### Endpoint /raw/list_object_map_entries ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. - **limit** (int | None) - Optional - The maximum number of entries to return. ### Response #### Success Response (200) - **entries** (list[tuple[int, int]]) - A list of tuples, where each tuple contains the object handle and its offset. ``` -------------------------------- ### Export DXF from Opened Document Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Export an already opened DWG document to DXF format. This method is called on the document object. ```python doc = ezdwg.read("examples/data/line_2000.dwg") doc.export_dxf("/tmp/line_2000_out.dxf") ``` -------------------------------- ### Convert DWG to DXF Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/cli.md Converts a DWG file to DXF format. Supports filtering entities by type, specifying DXF version, and enabling strict conversion mode. ```bash ezdwg convert input.dwg output.dxf ``` ```bash ezdwg convert input.dwg output.dxf --types "ARC LINE" ``` ```bash ezdwg convert input.dwg output.dxf --dxf-version R2018 ``` ```bash ezdwg convert input.dwg output.dxf --strict ``` -------------------------------- ### Open a DWG File Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/reading-files.md Use ezdwg.read() to open a DWG file. This function automatically detects the DWG version. ```python import ezdwg doc = ezdwg.read("path/to/file.dwg") ``` -------------------------------- ### Query Entities in Layout (Multiple Types) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Iterates over entities that match one of several specified types, like 'LINE', 'ARC', or 'CIRCLE'. Useful for processing groups of related entities. ```python # Multiple types for entity in msp.query("LINE ARC CIRCLE"): print(entity.dxftype, entity.handle) ``` -------------------------------- ### Plot DWG Directly from File Path Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/plotting.md Plot the contents of a DWG file by providing its path directly to the ezdwg.plot function. ```python import ezdwg ezdwg.plot("drawing.dwg") ``` -------------------------------- ### List DWG Section Locators Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists the locators for sections within a DWG file. Each locator includes the section name, offset, and size. ```python raw.list_section_locators(path: str) -> list[tuple[str, int, int]] ``` -------------------------------- ### Write DWG File Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/cli.md Writes a DWG file using the native AC1015 writer. Allows filtering entities, specifying DWG version, and enabling strict writing mode. ```bash ezdwg write input.dwg output.dwg ``` ```bash ezdwg write input.dwg output.dwg --types "LINE MTEXT" ``` ```bash ezdwg write input.dwg output.dwg --dwg-version AC1015 ``` ```bash ezdwg write input.dwg output.dwg --strict ``` -------------------------------- ### Enable Strict Mode for DWG to DXF Conversion Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/convert.md Perform DWG to DXF conversion in strict mode, which causes the process to fail if any entity cannot be written. ```python result = ezdwg.to_dxf( "input.dwg", "output.dxf", strict=True, ) ``` -------------------------------- ### Detect DWG Version Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Detects the DWG version string of a given file path. ```python raw.detect_version(path: str) -> str ``` -------------------------------- ### Filter Entities by Multiple Types (Arcs and Circles) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Queries and iterates over ARC and CIRCLE entities, printing their type, center, and radius. ```python # Multiple types for entity in msp.query("ARC CIRCLE"): print(entity.dxftype, entity.dxf["center"], entity.dxf["radius"]) ``` -------------------------------- ### Query Entities in Layout (Filtered by Type String) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Retrieves entities of a specific type, such as 'LINE', by providing the type name as a string. Useful for targeting specific entity types. ```python # Filter by type string for line in msp.query("LINE"): print(line.dxf["start"]) ``` -------------------------------- ### Convert DWG to DXF Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/core.md Converts a DWG file to DXF format. Supports filtering by entity type and specifying DXF version. Can operate in strict mode to fail on skipped entities. ```python import ezdwg # Example usage would go here, but the source only provides the function signature and description. ``` -------------------------------- ### Layout Class Definition Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Represents a drawing layout, such as modelspace, within a Document. It holds a reference to the document and the layout's name. ```python from dataclasses import dataclass @dataclass(frozen=True) class Layout: doc: Document name: str ``` -------------------------------- ### raw.list_section_locators Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists section locators for a given DWG file, returning their names, offsets, and sizes. ```APIDOC ## raw.list_section_locators ### Description List section locators. Each tuple: `(name, offset, size)`. ### Method GET ### Endpoint /raw/list_section_locators ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. ### Response #### Success Response (200) - **locators** (list[tuple[str, int, int]]) - A list of tuples, where each tuple contains the section name, offset, and size. ``` -------------------------------- ### raw.read_object_records_by_handle Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Reads raw object records by handle from a DWG file, returning handle, offset, size, type code, and data, with an optional limit. ```APIDOC ## raw.read_object_records_by_handle ### Description Read raw object records by handle. Each tuple: `(handle, offset, size, type_code, data)`. ### Method GET ### Endpoint /raw/read_object_records_by_handle ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. - **handles** (list[int]) - Required - A list of object handles to retrieve. - **limit** (int | None) - Optional - The maximum number of records to return. ### Response #### Success Response (200) - **records** (list[tuple[int, int, int, int, bytes]]) - A list of tuples containing handle, offset, size, type code, and raw data for the specified object handles. ``` -------------------------------- ### Query Entities in Layout (Iterable Types) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Filters entities by type using an iterable (e.g., a list) of type names. Provides flexibility in specifying multiple entity types for iteration. ```python # From an iterable for entity in msp.query(["LINE", "ARC"]): print(entity.dxftype) ``` -------------------------------- ### ezdwg.to_dwg Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/core.md Writes a DWG file using the native writer, supporting specific entity types and DWG versions. Returns a WriteResult object. ```APIDOC ## ezdwg.to_dwg ### Description Write a DWG file using the native writer. ### Parameters #### Path Parameters - `source` (str | Document | Layout) - Required - File path, Document, or Layout - `output_path` (str) - Required - Output DWG file path - `types` (str | Iterable[str] | None) - Optional - Entity type filter - `version` (str) - Optional - Output DWG version (currently AC1015 only). Default: `"AC1015"` - `strict` (bool) - Optional - Fail on skipped entities. Default: `False` ### Returns - `WriteResult` - A `WriteResult` object. ### Raises - `ValueError` - when an unsupported write version is requested, or in strict mode if entities are skipped. ### Supported native write entities (v1): - `LINE` - `RAY` - `XLINE` - `POINT` - `ARC` - `CIRCLE` - `LWPOLYLINE` - `TEXT` - `MTEXT` ``` -------------------------------- ### Low-Level API: Decode Line Entities Source: https://github.com/monozukuri-ai/ezdwg/blob/main/README.md Access the low-level API to decode specific entities like LINE from a DWG file. This provides raw access to the DWG structure. ```python from ezdwg import raw raw.decode_line_entities("path/to/file.dwg") ``` -------------------------------- ### Convert DWG to DWG (AC1015) Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/getting-started/quickstart.md Converts a DWG file to another DWG file using the native AC1015 writer. ```python import ezdwg result = ezdwg.to_dwg("input.dwg", "output.dwg", version="AC1015") print(f"Written: {result.written_entities}/{result.total_entities} entities") ``` -------------------------------- ### raw.list_object_headers_by_type Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists object headers filtered by specific type codes for a DWG file, with an optional limit. ```APIDOC ## raw.list_object_headers_by_type ### Description List object headers filtered by type codes. Each tuple: `(handle, offset, size, type_code, type_name, type_class)`. ### Method GET ### Endpoint /raw/list_object_headers_by_type ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. - **type_codes** (list[int]) - Required - A list of type codes to filter by. - **limit** (int | None) - Optional - The maximum number of headers to return. ### Response #### Success Response (200) - **headers** (list[tuple[int, int, int, int, str, str]]) - A list of tuples containing handle, offset, size, type code, type name, and type class for the filtered objects. ``` -------------------------------- ### Filter Entities by Type during DWG to DXF Conversion Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/convert.md Convert a DWG file to DXF, including only specified entity types like LINE, ARC, and LWPOLYLINE. ```python result = ezdwg.to_dxf( "input.dwg", "output.dxf", types="LINE ARC LWPOLYLINE", ) ``` -------------------------------- ### List Object Headers by Type Codes Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Lists object headers filtered by a specified list of type codes. An optional limit can be applied. ```python raw.list_object_headers_by_type(path: str, type_codes: list[int], limit: int | None = None) -> list[tuple[int, int, int, int, str, str]] ``` -------------------------------- ### Entity Class Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/entity.md Represents a DWG entity with its type, handle, and DXF attributes. Instances are typically obtained via layout queries. ```APIDOC ## Entity Class ### Description A DWG entity represented by its type, handle, and a dictionary of DXF attributes. These instances are returned by methods like `Layout.query()`. ### Fields | Field | Type | Description | |-------|------|-------------| | `dxftype` | `str` | Entity type name (e.g. "LINE", "ARC", "CIRCLE") | | `handle` | `int` | Unique handle within the DWG file | | `dxf` | `dict[str, Any]` | Entity attributes (type-specific) | ``` -------------------------------- ### Decode Entity Styles Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Decodes entity style information, including handle, color index, true color, and layer handle. An optional limit can be applied. ```python raw.decode_entity_styles(path: str, limit: int | None = None) -> list[tuple[int, int | None, int | None, int]] ``` -------------------------------- ### Read Raw Object Records by Handle Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Reads raw object records filtered by a specified list of handles, returning tuples of handle, offset, size, type code, and raw data. An optional limit can be applied. ```python raw.read_object_records_by_handle(path: str, handles: list[int], limit: int | None = None) -> list[tuple[int, int, int, int, bytes]] ``` -------------------------------- ### raw.decode_entity_styles Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Decodes entity style information (handle, color index, true color, layer handle) from a DWG file, with an optional limit. ```APIDOC ## raw.decode_entity_styles ### Description Decode entity style information. Each tuple: `(handle, color_index, true_color, layer_handle)`. ### Method GET ### Endpoint /raw/decode_entity_styles ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. - **limit** (int | None) - Optional - The maximum number of style records to return. ### Response #### Success Response (200) - **styles** (list[tuple[int, int | None, int | None, int]]) - A list of tuples containing entity handle, color index, true color, and layer handle. ``` -------------------------------- ### Document Class Definition Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/document.md Defines the structure of a DWG document, including its path, version, and decoding information. Created by ezdwg.read(). ```python from dataclasses import dataclass @dataclass(frozen=True) class Document: path: str version: str decode_path: str | None = None decode_version: str | None = None ``` -------------------------------- ### Entity Data Structure Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/entity.md Defines the data structure for a DWG entity, including its type, handle, and DXF attributes. Instances are returned by `Layout.query()`. ```python from dataclasses import dataclass from typing import Any @dataclass(frozen=True) class Entity: dxftype: str handle: int dxf: dict[str, Any] ``` -------------------------------- ### Bulk Decode Lines, Arcs, and Circles Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Optimized function to decode LINE, ARC, and CIRCLE entities in a single pass. It returns a tuple containing three lists: one for lines, one for arcs, and one for circles. ```python raw.decode_line_arc_circle_entities(path: str, limit: int | None = None) -> tuple[list, list, list] ``` -------------------------------- ### ezdwg.to_dxf Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/core.md Converts a DWG file to DXF format, with options to filter entities, specify DXF version, and control strictness. Returns a ConvertResult object. ```APIDOC ## ezdwg.to_dxf ### Description Convert a DWG file to DXF format. ### Parameters #### Path Parameters - `source` (str | Document | Layout) - Required - File path, Document, or Layout - `output_path` (str) - Required - Output DXF file path - `types` (str | Iterable[str] | None) - Optional - Entity type filter - `dxf_version` (str) - Optional - DXF version string. Default: `"R2010"` - `strict` (bool) - Optional - Fail on skipped entities. Default: `False` - `include_unsupported` (bool) - Optional - Query unsupported types. Default: `False` ### Returns - `ConvertResult` - A `ConvertResult` object. ### Raises - `ValueError` - in strict mode if entities are skipped. - `ImportError` - if ezdxf is not installed. ``` -------------------------------- ### raw.decode_document_graph Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Decodes a compact graph-oriented IR from a DWG file, returning comprehensive document data. ```APIDOC ## raw.decode_document_graph ### Description Decode a compact graph-oriented IR. The returned tuple contains: - DWG version string. - Object headers with resolved type names. - Common entity data: `(handle, type_name, owner_handle, color_index, true_color, layer_handle, linetype_handle, material_handle, plotstyle_handle, extension_dict_handle, reactor_handles)`. - Object graph edges: `(source_handle, kind, target_handle)`. - Layer table rows: `(handle, name, color_index, true_color)`. - Block header table rows: `(handle, name)`. - Header handle rows such as `("model_space_block_header", handle)`, current table handles such as `("clayer", handle)`, dictionaries, and table control handles such as `("layer_control", handle)`. When `limit` is provided, object rows are truncated first and graph rows are limited to those object handles. ### Method GET ### Endpoint /raw/decode_document_graph ### Parameters #### Query Parameters - **path** (str) - Required - The path to the DWG file. - **limit** (int | None) - Optional - Limits object and graph rows. ### Response #### Success Response (200) - **document_data** (tuple) - A tuple containing DWG version, object headers, entity data, graph edges, layer table rows, block header table rows, and header handle rows. ``` -------------------------------- ### Read Raw Object Records by Type Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/raw.md Reads raw object records filtered by type codes, returning tuples of handle, offset, size, type code, and raw data. An optional limit can be applied. ```python raw.read_object_records_by_type(path: str, type_codes: list[int], limit: int | None = None) -> list[tuple[int, int, int, int, bytes]] ``` -------------------------------- ### Entity Dataclass Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/index.md Provides access to Entity objects within a DWG file. ```APIDOC ## Entity Dataclass ### Description Provides access to Entity objects within a DWG file. ### Class - **Entity**: Represents an entity within a DWG file. ### Parameters Refer to the [Entity](entity.md) documentation for detailed information on the properties and methods of the Entity dataclass. ``` -------------------------------- ### Save Plot to File Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/guide/plotting.md Generate a plot from a DWG document without displaying it, and then save the plot to an image file using matplotlib. ```python import matplotlib.pyplot as plt import ezdwg doc = ezdwg.read("drawing.dwg") ax = doc.plot(show=False) plt.savefig("output.png", dpi=150, bbox_inches="tight") ``` -------------------------------- ### Entity.to_points Source: https://github.com/monozukuri-ai/ezdwg/blob/main/docs/api/entity.md Extracts key coordinate points from an entity. This method is crucial for geometric processing and visualization. ```APIDOC ## Entity.to_points() ### Description Extracts key coordinate points from the entity. This method is essential for geometric operations and rendering. ### Method `Entity.to_points() -> list[tuple[float, float, float]]` ### Returns List of 3D points representing significant coordinates of the entity. ### Raises `NotImplementedError` if the entity type is not supported. ### Supported Entity Types and Points Returned | Type | Points Returned | |------|----------------| | `LINE` | `[start, end]` | | `LWPOLYLINE` | All vertex points | | `POINT` | `[location]` | | `TEXT` | `[insert]` | | `MTEXT` | `[insert]` | | `DIMENSION` | `[defpoint2, defpoint3]` or `[text_midpoint]` | | `RAY` | `[start, start + unit_vector]` | | `XLINE` | `[start - unit_vector, start + unit_vector]` | ### Example ```python for entity in msp.query("LINE"): start, end = entity.to_points() print(f"Line from {start} to {end}") ``` ```