Skip to content

Export Mixin

Extracts entity data from the active drawing and exports to Excel (XLSX) or JSON.

The exported Excel file contains three sheets: Entities, Layers, and Blocks.

adapters.mixins.export_mixin.ExportMixin

Mixin for data extraction and export operations.

get_entity_counts

get_entity_counts() -> Dict[str, int]

Get instant counts of main entity types using SelectionSets (O(K)).

RETURNS DESCRIPTION
Dict[str, int]

Dictionary with counts mapping internal name to count:

Dict[str, int]

{ "Line": 120, "Polyline": 40, "LWPolyline": 15, "Circle":... }

extract_drawing_data

extract_drawing_data(
    only_selected: bool = False,
    limit: int = 500,
    offset: int = 0,
    entity_type: Optional[str] = None,
) -> list[dict]

Extract drawing data (entities) with their properties.

Optimized iteration through ModelSpace or selected entities with reduced COM calls. Uses property caching and batch processing for improved performance.

PARAMETER DESCRIPTION
only_selected

If True, extract only selected entities. If False, extract all. Defaults to False for backward compatibility.

TYPE: bool DEFAULT: False

limit

Maximum number of entities to return per page. Defaults to 500.

TYPE: int DEFAULT: 500

offset

Number of entities to skip before extracting. Defaults to 0.

TYPE: int DEFAULT: 0

entity_type

Optional DXF type name to filter by (e.g., 'LINE', 'LWPOLYLINE').

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
list[dict]

List of dictionaries with columns:

list[dict]
  • Handle: Entity handle (unique identifier)
list[dict]
  • ObjectType: Type of object (LINE, CIRCLE, LWPOLYLINE, etc.)
list[dict]
  • Layer: Layer name
list[dict]
  • Color: Color index (0-255) or color name
list[dict]
  • Length: Length (for linear objects)
list[dict]
  • Area: Area (for closed objects)
list[dict]
  • Radius: Radius (for circles and arcs)
list[dict]
  • Circumference: Circumference (2πr for circles, arc length for arcs)
list[dict]
  • Name: Name (for blocks, layers, etc.)

export_to_excel

export_to_excel(
    filepath: str = "drawing_data.xlsx",
) -> bool

Export drawing data to Excel file.

Uses the configured output directory from config.json for security, similar to save_drawing(). If only filename provided, saves to output directory.

PARAMETER DESCRIPTION
filepath

Path to output Excel file (default: "drawing_data.xlsx") - If filename only, saved to config output directory - If path provided, must be within output directory

TYPE: str DEFAULT: 'drawing_data.xlsx'

RETURNS DESCRIPTION
bool

True if successful, False otherwise