ActiveLayer Property (ActiveX)

Specifies the active layer.

Supported platforms: Windows only

Signature

VBA:

object.ActiveLayer
object

Type: Document

The object this property applies to.

Property Value

Read-only: No

Type: Layer

The layer that is currently active.

Remarks

New objects are placed on the active layer as they are created. To change the layer on which an existing object resides, use the Layer property for that object.

To create a new layer, use the Add method.

To change the visibility or another property of a layer, refer to the Layer object.

Examples

VBA:

Sub Example_ActiveLayer()
    ' This example returns the current layer
    ' and then adds a new layer.
    ' Finally, it returns the layer to the previous setting.
    Dim currLayer As AcadLayer
    Dim newLayer As AcadLayer
    
    ' Return the current layer of the active document
    Set currLayer = ThisDrawing.ActiveLayer
    MsgBox "The current layer is " & currLayer.name, vbInformation, "ActiveLayer Example"
    
    ' Create a Layer and make it the active layer
    Set newLayer = ThisDrawing.Layers.Add("TestLayer")
    ThisDrawing.ActiveLayer = newLayer
    MsgBox "The new layer is " & newLayer.name, vbInformation, "ActiveLayer Example"

    ' Reset the layer to its previous setting
    ThisDrawing.ActiveLayer = currLayer
    MsgBox "The active layer is reset to " & currLayer.name, vbInformation, "ActiveLayer Example"
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_ActiveLayer()
    ;; This example returns the current layer
    ;; and then adds a new layer.
    ;; Finally, it returns the layer to the previous setting.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Return the current layer of the active document
    (setq currLayer (vla-get-ActiveLayer doc))
    (alert (strcat "The current layer is " (vla-get-Name currLayer)))
    
    ;; Create a Layer and make it the active layer
    (setq layers (vla-get-Layers doc))
    (setq newLayer (vla-Add layers "TestLayer"))
    (alert (strcat "The new layer is " (vla-get-Name newLayer)))

    ;; Restore the previous layer
    (setq currLayer (vla-get-ActiveLayer doc))
    (alert (strcat "The active layer is restored to " (vla-get-Name currLayer)))
)