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:
|
entity_handles
|
List of entity handles to include in block
TYPE:
|
insertion_point
|
Base point for block definition (default: 0,0,0)
TYPE:
|
description
|
Optional block description
TYPE:
|
| 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:
|
insertion_point
|
Base point for block definition (default: 0,0,0)
TYPE:
|
description
|
Optional block description
TYPE:
|
| 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:
|
insertion_point
|
Point where to insert the block (x,y) or (x,y,z)
TYPE:
|
scale_x
|
X scale factor (default: 1.0)
TYPE:
|
scale_y
|
Y scale factor (default: 1.0)
TYPE:
|
scale_z
|
Z scale factor (default: 1.0)
TYPE:
|
rotation
|
Rotation angle in degrees (default: 0.0)
TYPE:
|
layer
|
Layer to place the block on (default: "0")
TYPE:
|
color
|
Color for the block reference (default: "white")
TYPE:
|
attributes
|
Dictionary of attribute tag -> value pairs to set (optional)
TYPE:
|
_skip_refresh
|
Internal flag to skip view refresh (used for batch operations)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Handle of the inserted block reference |
| RAISES | DESCRIPTION |
|---|---|
CADOperationError
|
If block doesn't exist or insertion fails |
list_blocks
¶
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 instant counts of block insertions using SelectionSets.
| PARAMETER | DESCRIPTION |
|---|---|
block_names
|
Optional list of specific blocks to count. If None, counts all blocks.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, int]
|
Dictionary mapping block names to insertion counts |
get_block_info
¶
Get detailed information about a block definition.
| PARAMETER | DESCRIPTION |
|---|---|
block_name
|
Name of the block
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
Dictionary with block information: |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
get_block_references
¶
Get all references (instances) of a specific block in the drawing.
| PARAMETER | DESCRIPTION |
|---|---|
block_name
|
Name of the block to find references for
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Dict[str, Any]]
|
List of dictionaries with reference information: |
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
get_block_attributes
¶
Get all attributes from a block reference.
| PARAMETER | DESCRIPTION |
|---|---|
handle
|
Handle of the block reference entity
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, str]
|
Dictionary of attribute tag -> value pairs |
set_block_attributes
¶
Set attributes on a block reference.
| PARAMETER | DESCRIPTION |
|---|---|
handle
|
Handle of the block reference entity
TYPE:
|
attributes
|
Dictionary of attribute tag -> value pairs to set
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if at least one attribute was set, False otherwise |