Skip to content

Raw API

The ezdwg.raw module provides low-level access to the Rust decode functions. These functions return data as tuples for maximum performance.

Angle Units

The raw API returns ARC angles in radians, unlike the high-level API which uses degrees.

Object Metadata and Boundaries

decode_object_eed

raw.decode_object_eed(path) returns XDATA for entities and non-graphical objects in object-map order. Each row is (handle, [(app_handle, app_name, [(group_code, value)])]). Group codes use the DXF range (1000 and above); handle values are integers and binary values are bytes. An unresolved application name is None. Unreadable records are omitted in best-effort mode. Public fixtures cover R14 through R2018.

EED handle values (groups 1003 and 1005) are read in big-endian order. This also corrects the previously byte-reversed values from decode_layer_eed.

decode_header_variables

raw.decode_header_variables(path) preserves its eleven-element tuple: (insunits, lunits, luprec, aunits, auprec, ltscale, textsize, extmin, extmax, limmin, limmax). Pass include_xclipframe=True to append a twelfth value: $XCLIPFRAME (0, 1 or 2), or None before R2004 or when unreadable. Document.header_variables() includes the xclipframe key automatically.

decode_spatial_filters

raw.decode_spatial_filters(path) returns (handle, owner, points, extrusion, origin, displayed, front, back, inverse_block_transform, boundary_transform) for each readable SPATIAL_FILTER. The owner is a dictionary handle or None. Points lie in the boundary plane; two points describe opposite corners of a rectangle. Front/back distances are None when disabled; each transform contains twelve stored reals. Truncated data and non-finite numbers are rejected. Public R14–R2018 samples cover rectangular clips without front/back distances; constructed records cover back-clipping distance and malformed input.

decode_dictionary_owners

raw.decode_dictionary_owners(path) returns (dictionary_handle, owner_handle, [(entry_name, value_handle)]) in object-map order. Owner/value handles can be None. R2000 and later are covered by public fixtures. Follow the SPATIAL and ACAD_FILTER entries and their dictionary owners to find the INSERT clipped by a spatial filter.

decode_table_placements

raw.decode_table_placements(path) returns (handle, insert, scale, rotation, extrusion, block_header_handle) for readable ACAD_TABLE placement records. Rotation is in radians; an unresolved block handle is None. Public R14–R2018 samples reference anonymous *T blocks that draw the table. Cell data is not decoded.

decode_hatch_boundaries

raw.decode_hatch_boundaries(path) returns (handle, paths) for readable HATCH entities. Each path is ("polyline", closed, vertices, bulges) or ("edges", edges). Bulges are empty when absent. Edge rows are:

  • ("line", start, end)
  • ("arc", center, radius, start_angle, end_angle, ccw)
  • ("ellipse", center, major_axis, ratio, start_angle, end_angle, ccw)
  • ("spline", degree, rational, periodic, knots, control_points, weights, fit_points, start_tangent, end_tangent)

Angles are in radians; coordinates are in the HATCH plane. Optional spline tangents are None when absent. These rows retain curve definitions, while the existing entity/path API continues to return sampled points. Existing best-effort HATCH recovery still applies; this API does not certify a damaged record or preserve every HATCH property needed for a lossless rewrite.

decode_write_blocks

Block metadata rows additionally expose xref, overlay and xref_path. External-reference metadata is read only; the bounded writer continues to report unsupported xref semantics through the existing losses field. The xref/overlay count-layout fix has constructed-record coverage; the public sample corpus contains no external-reference drawing.

File Inspection

detect_version

raw.detect_version(path: str) -> str

Detect the DWG version string (e.g. "AC1015").

list_section_locators

raw.list_section_locators(path: str) -> list[tuple[str, int, int]]

List section locators. Each tuple: (name, offset, size).

list_object_map_entries

raw.list_object_map_entries(path: str, limit: int | None = None) -> list[tuple[int, int]]

List object map entries. Each tuple: (handle, offset).

list_object_headers

raw.list_object_headers(path: str, limit: int | None = None) -> list[tuple[int, int, int, int]]

List object headers. Each tuple: (handle, offset, size, type_code).

list_object_headers_with_type

raw.list_object_headers_with_type(path: str, limit: int | None = None) -> list[tuple[int, int, int, int, str, str]]

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.

list_object_type_names

raw.list_object_type_names(path: str) -> list[str]

Return unique resolved DWG type names in order of first appearance in the object map. Includes entity, object, and unsupported types. Reads the shared native catalog without transferring the full header table to Python.

list_object_handles_by_type_name

raw.list_object_handles_by_type_name(path: str, type_name: str, limit: int | None = None) -> list[int]

Return handles matching an exact resolved DWG type name, ignoring case and surrounding whitespace. Dynamic class names are included. Object-map order and duplicate handles are preserved. Use names such as DIM_LINEAR as returned by list_object_type_names; high-level aliases such as DIMENSION are not expanded. An empty name or a limit of zero returns an empty list.

decode_document_graph

raw.decode_document_graph(path: str, limit: int | None = None) -> tuple[
    str,
    list[tuple[int, int, int, int, str, str]],
    list[
        tuple[
            int,
            str,
            int | None,
            int | None,
            int | None,
            int,
            int | None,
            int | None,
            int | None,
            int | None,
            list[int],
        ]
    ],
    list[tuple[int, str, int]],
    list[tuple[int, str | None, int | None, int | None]],
    list[tuple[int, str]],
    list[tuple[str, int | None]],
]

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.

list_object_headers_by_type

raw.list_object_headers_by_type(path: str, type_codes: list[int], limit: int | None = None) -> list[tuple[int, int, int, int, str, str]]

List object headers filtered by type codes.

Object Record Access

read_object_records_by_type

raw.read_object_records_by_type(path: str, type_codes: list[int], limit: int | None = None) -> list[tuple[int, int, int, int, bytes]]

Read raw object records by type code. Each tuple: (handle, offset, size, type_code, data).

read_object_records_by_handle

raw.read_object_records_by_handle(path: str, handles: list[int], limit: int | None = None) -> list[tuple[int, int, int, int, bytes]]

Read raw object records by handle.

decode_entity_proxy_graphics

raw.decode_entity_proxy_graphics(path: str, handles: list[int], limit: int | None = None) -> list[tuple[int, bytes | None]]

The proxy graphic of entities, by handle. Each tuple: (handle, graphic); graphic is None when the entity has no proxy graphic. A handle with no tuple was not read. R14 to R2018. See Proxy Graphic of an Entity.

decode_object_handle_stream_refs

raw.decode_object_handle_stream_refs(path: str, handles: list[int], limit: int | None = None) -> list[tuple[int, list[int]]]

Decode handle-stream references for objects. Each tuple: (handle, ref_handles).

Style and Layer Data

decode_entity_styles

raw.decode_entity_styles(path: str, limit: int | None = None) -> list[tuple[int, int | None, int | None, int]]

Decode entity style information. Each tuple: (handle, color_index, true_color, layer_handle).

decode_layer_colors

raw.decode_layer_colors(path: str, limit: int | None = None) -> list[tuple[int, int, int | None]]

Decode layer color information. Each tuple: (handle, color_index, true_color).

decode_layer_names

raw.decode_layer_names(path: str, limit: int | None = None) -> list[tuple[int, str]]

Decode the layer table. Each tuple: (handle, name).

Linetype Data

decode_linetypes

raw.decode_linetypes(path: str, limit: int | None = None) -> list[tuple[int, str, str, float, list[float]]]

Decode the linetype table. Each tuple: (handle, name, description, pattern_length, dashes). dashes is the dash pattern in drawing units at linetype scale 1, with the DXF sign convention: positive = dash, negative = gap, 0 = dot. The table includes the built-in ByBlock, ByLayer and Continuous entries, whose pattern is empty.

decode_linetype_elements

raw.decode_linetype_elements(path: str, limit: int | None = None) -> list[tuple[int, str, list[tuple[float, int, int, float, float, float, float, int | None, str | None]]]]

Decode the complex elements of the linetype table. Each tuple: (handle, name, elements), one element per dash in dash order: (length, flags, shape_code, x_offset, y_offset, scale, rotation, style_handle, text). flags 0x02 marks a text element and 0x04 a shape; rotation is in radians as stored. style_handle is the STYLE record of the text font or shape file, None when not set. text is the string of a text element, else None. A record whose elements cannot be read is left out; its plain dashes are still in decode_linetypes.

decode_layer_linetypes

raw.decode_layer_linetypes(path: str, limit: int | None = None) -> list[tuple[int, int]]

Linetype of every layer. Each tuple: (layer_handle, linetype_handle).

decode_entity_linetypes

raw.decode_entity_linetypes(path: str, limit: int | None = None) -> list[tuple[int, int, int, int | None, float]]

Linetype of every entity. Each tuple: (handle, layer_handle, linetype_flags, linetype_handle, linetype_scale).

linetype_flags Meaning
0 BYLAYER: the linetype of layer_handle
1 BYBLOCK
2 CONTINUOUS
3 The linetype named by linetype_handle

linetype_scale is the entity's own linetype scale (DXF group 48). The rows come from the common entity data, so they cover every entity type, including the ones without a geometry decoder, and layer_handle is the layer stored there.

A dash of an entity is dash * $LTSCALE * linetype_scale drawing units long ($LTSCALE is Document.header_variables()["ltscale"]).

Layer State and Lineweights

decode_layer_states

raw.decode_layer_states(path: str, limit: int | None = None) -> list[tuple[int, bool, bool, bool, bool, bool, int]]

State of every layer. Each tuple: (layer_handle, frozen, off, frozen_in_new_viewports, locked, plot, lineweight).

lineweight is in hundredths of a millimetre, as DXF group 370 writes it: -3 is the default lineweight, -1 BYLAYER and -2 BYBLOCK. R13/R14 files have neither a plot flag nor lineweights: plot is True and lineweight is -3 for every layer.

A layer that is off or frozen shows none of its entities; a layer with plot = False is displayed but not printed.

decode_dimstyles

raw.decode_dimstyles(path: str, limit: int | None = None) -> list[tuple[int, str, float, float, float]]

Sizes of every dimension style. Each tuple: (handle, name, dimscale, dimasz, dimtxt): the overall scale (0 for a style scaled by the viewport or annotatively), the arrow size and the text height.

decode_layout_objects

raw.decode_layout_objects(path: str, limit: int | None = None) -> list[tuple]

Layouts of the drawing (the model tab and the paper-space sheets). Each tuple: (handle, name, tab_order, flags, block_record_handle, paper, limits, extents, viewport_handles, last_active_viewport_handle, plot).

  • paper: (paper_width, paper_height, (left, bottom, right, top) margins, paper_size_name, paper_units, plot_rotation). Sizes are millimetres before the plot rotation (0-3 quarter turns counter-clockwise); paper_units is 0 for inches, 1 for millimetres and 2 for pixels.
  • limits and extents: (min, max) in layout units.
  • viewport_handles: the viewports of the layout, the sheet's own viewport first (R2004+; empty before).
  • plot: (plot_flags, plot_origin, plot_type, window_min, window_max, scale_numerator, scale_denominator, scale_type, scale_factor).

Layouts whose record cannot be read are omitted.

decode_viewport_details

raw.decode_viewport_details(path: str, limit: int | None = None) -> list[tuple]

Paper-space viewports. Each tuple: (handle, center, width, height, view, frozen_layer_handles, clip_boundary_handle, layer_handle).

center, width and height place the viewport on its sheet; center is None when the body of the viewport cannot be read. view is (target, direction, twist_angle, view_height, lens_length, front_clip_z, back_clip_z, view_center, status_flags, render_mode) with the twist angle in radians, or None for R13/R14 files, which keep the view in the extended data of the entity. decode_viewport_entities still returns the handles alone.

decode_entity_lineweights

raw.decode_entity_lineweights(path: str, limit: int | None = None) -> list[tuple[int, int | None, bool]]

Lineweight and visibility of every entity. Each tuple: (handle, lineweight, invisible). lineweight uses the values above (-1 when the entity takes the lineweight of its layer) and is None for R13/R14 files. invisible is the invisibility flag of the entity (DXF group 60).

Like decode_entity_linetypes, the rows come from the common entity data and cover every entity type.

Geometry Decode Functions

All geometry decode functions take a path and optional limit parameter.

decode_line_entities

raw.decode_line_entities(path: str, limit: int | None = None) -> list[tuple[int, float, float, float, float, float, float]]

Each tuple: (handle, start_x, start_y, start_z, end_x, end_y, end_z).

decode_arc_entities

raw.decode_arc_entities(path: str, limit: int | None = None) -> list[tuple[int, float, float, float, float, float, float]]

Each tuple: (handle, center_x, center_y, center_z, radius, start_angle, end_angle).

Warning

Angles are in radians.

decode_circle_entities

raw.decode_circle_entities(path: str, limit: int | None = None) -> list[tuple[int, float, float, float, float]]

Each tuple: (handle, center_x, center_y, center_z, radius).

decode_point_entities

raw.decode_point_entities(path: str, limit: int | None = None) -> list[tuple[int, float, float, float, float]]

Each tuple: (handle, x, y, z, thickness).

decode_ellipse_entities

raw.decode_ellipse_entities(path: str, limit: int | None = None) -> list[tuple[int, ...]]

Each tuple: (handle, center, extrusion, major_axis, ratio, start_angle, end_angle).

decode_lwpolyline_entities

raw.decode_lwpolyline_entities(path: str, limit: int | None = None) -> list[tuple[int, int, list[tuple[float, float]], list[float], list[tuple[float, float]], float | None]]

Each tuple: (handle, flags, points, bulges, widths, const_width).

decode_text_entities

raw.decode_text_entities(path: str, limit: int | None = None) -> list[tuple[int, str, ...]]

Decode TEXT entities with text content, insertion point, alignment, and style information.

decode_mtext_entities

raw.decode_mtext_entities(path: str, limit: int | None = None) -> list[tuple[int, str, ...]]

Decode MTEXT entities with text content, insertion point, size, and attachment information.

decode_dimension_entities

raw.decode_dimension_entities(path: str, limit: int | None = None) -> list[tuple]

Decode all DIMENSION entity subtypes. Returns (dimtype, row) pairs; row is the 12-tuple shared by every decode_dim_*_entities function: (handle, user_text, defpoint(10), defpoint2(13), defpoint3(14), text_midpoint(11), insert_point(12) | None, (extrusion, insert_scale), (text_rotation, horizontal_direction, ext_line_rotation, dim_rotation), (dim_flags, actual_measurement, attachment_point, line_spacing_style, line_spacing_factor, insert_rotation), (dimstyle_handle, anonymous_block_handle), (point15 | None, point16 | None)). The last element carries the type-specific extra points: DXF code 15 for ANG3PT/ANG2LN/RADIUS/DIAMETER and code 16 ((x, y)) for ANG2LN; other types yield (None, None). anonymous_block_handle is the BLOCK_HEADER that holds the saved graphics of the dimension (None when the dimension has no block); the entities of that block have it as their owner handle.

decode_insert_entities

raw.decode_insert_entities(path: str, limit: int | None = None) -> list[tuple[int, float, float, float, float, float, float, float, str | None]]

Each tuple: (handle, x, y, z, xscale, yscale, zscale, rotation, block_name).

Bulk Decode

decode_line_arc_circle_entities

raw.decode_line_arc_circle_entities(path: str, limit: int | None = None) -> tuple[list, list, list]

Decode LINE, ARC, and CIRCLE entities in a single pass for better performance. Returns a 3-tuple of (lines, arcs, circles).

Usage Example

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}°")

decode_hatch_patterns

raw.decode_hatch_patterns(path: str, limit: int | None = None) -> list[tuple[int, float, float, bool, list[tuple[float, tuple[float, float], tuple[float, float], list[float]]]]]

Pattern definition of every pattern-filled hatch. Each tuple: (handle, pattern_angle, pattern_scale, double, lines), with one (angle, base, offset, dashes) per family of parallel pattern lines. Angles are in radians. The lines are stored already rotated and scaled: line k of a family runs through base + k * offset at angle, dashed by dashes (empty = continuous). Solid fills and hatches whose definition cannot be read have no row.