Skip to content

Block Mixin

Block definition and insertion management, including attribute read/write.

adapters.mixins.block_mixin.BlockMixin

Mixin for block operations.

create_block_from_entities

create_block_from_entities(
    block_name: str,
    entity_handles: List[str],
    insertion_point: Coordinate = (0.0, 0.0, 0.0),
    description: str = "",
) -> Dict[str, Any]

Create a block from specified entities.

PARAMETER DESCRIPTION
block_name

Name for the new block

TYPE: str

entity_handles

List of entity handles to include in block

TYPE: List[str]

insertion_point

Base point for block definition (default: 0,0,0)

TYPE: Coordinate DEFAULT: (0.0, 0.0, 0.0)

description

Optional block description

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
Dict[str, Any]

Dictionary with operation status and details

RAISES DESCRIPTION
CADOperationError

If block creation fails

InvalidParameterError

If parameters are invalid

create_block_from_selection

create_block_from_selection(
    block_name: str,
    insertion_point: Coordinate = (0.0, 0.0, 0.0),
    description: str = "",
) -> Dict[str, Any]

Create a block from currently selected entities.

PARAMETER DESCRIPTION
block_name

Name for the new block

TYPE: str

insertion_point

Base point for block definition (default: 0,0,0)

TYPE: Coordinate DEFAULT: (0.0, 0.0, 0.0)

description

Optional block description

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
Dict[str, Any]

Dictionary with operation status and details

RAISES DESCRIPTION
CADOperationError

If block creation fails or no entities selected

InvalidParameterError

If parameters are invalid

insert_block

insert_block(
    block_name: str,
    insertion_point: Coordinate,
    scale_x: float = 1.0,
    scale_y: float = 1.0,
    scale_z: float = 1.0,
    rotation: float = 0.0,
    layer: str = "0",
    color: str = "white",
    attributes: Dict[str, str] | None = None,
    _skip_refresh: bool = False,
) -> str

Insert a block reference in the drawing.

PARAMETER DESCRIPTION
block_name

Name of the block to insert

TYPE: str

insertion_point

Point where to insert the block (x,y) or (x,y,z)

TYPE: Coordinate

scale_x

X scale factor (default: 1.0)

TYPE: float DEFAULT: 1.0

scale_y

Y scale factor (default: 1.0)

TYPE: float DEFAULT: 1.0

scale_z

Z scale factor (default: 1.0)

TYPE: float DEFAULT: 1.0

rotation

Rotation angle in degrees (default: 0.0)

TYPE: float DEFAULT: 0.0

layer

Layer to place the block on (default: "0")

TYPE: str DEFAULT: '0'

color

Color for the block reference (default: "white")

TYPE: str DEFAULT: 'white'

attributes

Dictionary of attribute tag -> value pairs to set (optional)

TYPE: Dict[str, str] | None DEFAULT: None

_skip_refresh

Internal flag to skip view refresh (used for batch operations)

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
str

Handle of the inserted block reference

RAISES DESCRIPTION
CADOperationError

If block doesn't exist or insertion fails

list_blocks

list_blocks() -> List[str]

Get list of all block definitions in the drawing.

RETURNS DESCRIPTION
List[str]

List of block names (excludes system blocks that start with *)

Note

System blocks (like Model_Space, Paper_Space) are filtered out

get_block_counts

get_block_counts(
    block_names: List[str] | None = None,
) -> Dict[str, int]

Get instant counts of block insertions using SelectionSets.

PARAMETER DESCRIPTION
block_names

Optional list of specific blocks to count. If None, counts all blocks.

TYPE: List[str] | None DEFAULT: None

RETURNS DESCRIPTION
Dict[str, int]

Dictionary mapping block names to insertion counts

get_block_info

get_block_info(block_name: str) -> Dict[str, Any]

Get detailed information about a block definition.

PARAMETER DESCRIPTION
block_name

Name of the block

TYPE: str

RETURNS DESCRIPTION
Dict[str, Any]

Dictionary with block information:

Dict[str, Any]
  • Name: Block name
Dict[str, Any]
  • Origin: Block insertion base point (x, y, z)
Dict[str, Any]
  • ObjectCount: Number of entities in the block
Dict[str, Any]
  • IsXRef: Whether the block is an external reference
Dict[str, Any]
  • Comments: Block comments/description

get_block_references

get_block_references(
    block_name: str,
) -> List[Dict[str, Any]]

Get all references (instances) of a specific block in the drawing.

PARAMETER DESCRIPTION
block_name

Name of the block to find references for

TYPE: str

RETURNS DESCRIPTION
List[Dict[str, Any]]

List of dictionaries with reference information:

List[Dict[str, Any]]
  • Handle: Block reference handle
List[Dict[str, Any]]
  • InsertionPoint: Insertion point (x, y, z)
List[Dict[str, Any]]
  • ScaleFactors: Scale factors (x, y, z)
List[Dict[str, Any]]
  • Rotation: Rotation angle in degrees
List[Dict[str, Any]]
  • Layer: Layer name

get_block_attributes

get_block_attributes(handle: str) -> Dict[str, str]

Get all attributes from a block reference.

PARAMETER DESCRIPTION
handle

Handle of the block reference entity

TYPE: str

RETURNS DESCRIPTION
Dict[str, str]

Dictionary of attribute tag -> value pairs

set_block_attributes

set_block_attributes(
    handle: str, attributes: Dict[str, str]
) -> bool

Set attributes on a block reference.

PARAMETER DESCRIPTION
handle

Handle of the block reference entity

TYPE: str

attributes

Dictionary of attribute tag -> value pairs to set

TYPE: Dict[str, str]

RETURNS DESCRIPTION
bool

True if at least one attribute was set, False otherwise