Jump to content

AutoCAD VBA - change active layer


katto01

Recommended Posts

Hello,

 

I am trying to change the change the active layer.

 

I tried this routine but no luck.

 

Public Sub ChangeEntityLayer()

 

Dim objEntity As AcadEntity

Dim varPick As Variant

Dim strLayerName As String

Dim objLayer As AcadLayer

 

strLayerName="Mypoints"

 

Set objLayer = ThisDrawing.Layers(strLayerName)

End Sub

 

Any ideas?

 

Thank you

Link to comment
Share on other sites

26 minutes ago, katto01 said:

Hello,

 

I am trying to change the change the active layer.

 

I tried this routine but no luck.

 

Public Sub ChangeEntityLayer()

 

Dim objEntity As AcadEntity

Dim varPick As Variant

Dim strLayerName As String

Dim objLayer As AcadLayer

 

strLayerName="Mypoints"

 

Set objLayer = ThisDrawing.Layers(strLayerName)

End Sub

 

Any ideas?

 

Thank you

See On line Hep for Active Layer 

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

What you are trying to do with below code it's for retrieving all layers collection in the drawing not for set layer.

Dim objLayer As AcadLayers

 

strLayerName="Mypoints" 'could be used to create new layer and make it as active layer.

 

Set objLayer = ThisDrawing.Layers(strLayerName)

Set objLayer = ThisDrawing.Layers

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...