Jump to content
katto01

AutoCAD VBA - change active layer

Recommended Posts

katto01

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

Share this post


Link to post
Share on other sites
PeterPan9720
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

Share this post


Link to post
Share on other sites
katto01

Great, Thanks

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...