Skip to content

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_layer(
    name: str,
    color: str | int = "white",
    lineweight: int = 0,
) -> bool

Create a new layer in the active drawing via COM.

PARAMETER DESCRIPTION
name

Name for the new layer.

TYPE: str

color

Layer color as a name (e.g. "red") or ACI index. Default: "white".

TYPE: str | int DEFAULT: 'white'

lineweight

Line weight in hundredths of a millimetre (e.g. 25 = 0.25 mm). Use 0 for the default line weight.

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
bool

True if the layer was created successfully, False otherwise.

set_current_layer

set_current_layer(name: str) -> bool

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: str

RETURNS DESCRIPTION
bool

True if successful, False otherwise.

get_current_layer

get_current_layer() -> str

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 "0" if undetermined.

list_layers

list_layers() -> List[str]

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_layers_info(
    entity_data: Optional[List[Dict[str, Any]]] = None,
) -> List[Dict[str, Any]]

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: Optional[List[Dict[str, Any]]] DEFAULT: None

RETURNS DESCRIPTION
List[Dict[str, Any]]

List of dictionaries with layer information:

List[Dict[str, Any]]
  • Name: Layer name
List[Dict[str, Any]]
  • ObjectCount: Number of objects on the layer
List[Dict[str, Any]]
  • Color: Layer color
List[Dict[str, Any]]
  • Linetype: Layer linetype
List[Dict[str, Any]]
  • Lineweight: Layer lineweight
List[Dict[str, Any]]
  • IsLocked: Whether layer is locked
List[Dict[str, Any]]
  • IsVisible: Whether layer is visible

rename_layer

rename_layer(old_name: str, new_name: str) -> bool

Rename an existing layer via COM.

Layer "0" cannot be renamed.

PARAMETER DESCRIPTION
old_name

Current name of the layer to rename.

TYPE: str

new_name

New name for the layer.

TYPE: str

RETURNS DESCRIPTION
bool

True if renamed successfully, False otherwise.

delete_layer

delete_layer(name: str) -> bool

Delete a layer from the active drawing via COM.

Layer "0" cannot be deleted.

PARAMETER DESCRIPTION
name

Name of the layer to delete.

TYPE: str

RETURNS DESCRIPTION
bool

True if deleted successfully, False otherwise.

turn_layer_on

turn_layer_on(name: str) -> bool

Make a frozen layer visible by unfreezing it via COM.

PARAMETER DESCRIPTION
name

Name of the layer to turn on.

TYPE: str

RETURNS DESCRIPTION
bool

True if successful, False otherwise.

turn_layer_off

turn_layer_off(name: str) -> bool

Hide a layer by freezing it via COM.

PARAMETER DESCRIPTION
name

Name of the layer to turn off.

TYPE: str

RETURNS DESCRIPTION
bool

True if successful, False otherwise.

is_layer_on

is_layer_on(name: str) -> bool

Check whether a layer is currently visible (not frozen) via COM.

PARAMETER DESCRIPTION
name

Name of the layer to check.

TYPE: str

RETURNS DESCRIPTION
bool

True if the layer is visible, False if frozen or on error.

set_layer_color

set_layer_color(layer_name: str, color: str | int) -> bool

Set the color of a layer.

PARAMETER DESCRIPTION
layer_name

Name of the layer to modify

TYPE: str

color

Color name (from COLOR_MAP) or ACI index (1-255)

TYPE: str | int

RETURNS DESCRIPTION
bool

True if successful, False otherwise

TYPE: bool

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_color_bylayer(
    handles: List[str],
) -> Dict[str, Any]

Set entities to use their layer's color (ByLayer).

PARAMETER DESCRIPTION
handles

List of entity handles to modify

TYPE: List[str]

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: Dict[str, Any]

Note
  • Assigns color value 256 (acByLayer) to entities
  • Entities will inherit their layer's color
  • Uses TrueColor property (modern method)