Layer Mixin¶
Full layer lifecycle management: create, rename, delete, toggle visibility, and query.
adapters.mixins.layer_mixin.LayerMixin
¶
Mixin for layer management operations.
create_layer
¶
Create a new layer in the active drawing via COM.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name for the new layer.
TYPE:
|
color
|
Layer color as a name (e.g.
TYPE:
|
lineweight
|
Line weight in hundredths of a millimetre (e.g. 25 = 0.25 mm). Use 0 for the default line weight.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the layer was created successfully, False otherwise. |
set_current_layer
¶
Set the active (current) drawing layer via COM.
New entities will be created on this layer by default.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of an existing layer to make current.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if successful, False otherwise. |
get_current_layer
¶
Return the name of the currently active layer.
Falls back to the cached drawing state if the COM call fails.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Active layer name string, or |
list_layers
¶
Return the names of all layers in the active drawing via COM.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of layer name strings. Empty list on error. |
get_layers_info
¶
Get detailed information about all layers.
Optimized to count entities per layer in a single pass using direct iteration, or from pre-extracted entity data to avoid re-iterating ModelSpace.
| PARAMETER | DESCRIPTION |
|---|---|
entity_data
|
Optional pre-extracted entity data. If provided, layer counts will be computed from this data instead of iterating ModelSpace.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Dict[str, Any]]
|
List of dictionaries with layer information: |
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
|
rename_layer
¶
Rename an existing layer via COM.
Layer "0" cannot be renamed.
| PARAMETER | DESCRIPTION |
|---|---|
old_name
|
Current name of the layer to rename.
TYPE:
|
new_name
|
New name for the layer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if renamed successfully, False otherwise. |
delete_layer
¶
Delete a layer from the active drawing via COM.
Layer "0" cannot be deleted.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the layer to delete.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if deleted successfully, False otherwise. |
turn_layer_on
¶
Make a frozen layer visible by unfreezing it via COM.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the layer to turn on.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if successful, False otherwise. |
turn_layer_off
¶
Hide a layer by freezing it via COM.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the layer to turn off.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if successful, False otherwise. |
is_layer_on
¶
Check whether a layer is currently visible (not frozen) via COM.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the layer to check.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the layer is visible, False if frozen or on error. |
set_layer_color
¶
Set the color of a layer.
| PARAMETER | DESCRIPTION |
|---|---|
layer_name
|
Name of the layer to modify
TYPE:
|
color
|
Color name (from COLOR_MAP) or ACI index (1-255)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if successful, False otherwise
TYPE:
|
Note
- Uses the modern TrueColor property (recommended by Autodesk)
- Accepts color names: "red", "blue", "green", etc.
- Accepts ACI index: 1-255
- Color value 256 (bylayer) is not valid for layers
set_entities_color_bylayer
¶
Set entities to use their layer's color (ByLayer).
| PARAMETER | DESCRIPTION |
|---|---|
handles
|
List of entity handles to modify
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Result summary with counts and details: - total: Total entities processed - changed: Number successfully changed to ByLayer - failed: Number that failed - results: List of per-entity results
TYPE:
|
Note
- Assigns color value 256 (acByLayer) to entities
- Entities will inherit their layer's color
- Uses TrueColor property (modern method)