Highlight drawed entities by layer name

Highlight drawed entities by layer name

Anonymous
Nicht anwendbar
862Aufrufe
7Antworten
Nachricht 1 von 8

Highlight drawed entities by layer name

Anonymous
Nicht anwendbar

I have a drawing with two drawingentities.

 

a circle drawed in the layer named "layer01" and

a line drawed in the layer named "layer02"

 

Now I want a vba code that select (highlight) all drawed entities in layer01 and layer02.

That's all

 

Is that possible in VBA?

 

gr. Laszlo

 

 

0 „Gefällt mir“-Angaben
Akzeptierte Lösungen (1)
863Aufrufe
7Antworten
Antworten (7)
Nachricht 2 von 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

Public Sub HighlightTest()
   Dim tSelSet As AcadSelectionSet
   Set tSelSet = getSelSetByLayer("Layer01")
   If tSelSet Is Nothing Then
      MsgBox ("No Selectionset")
   ElseIf tSelSet.Count = 0 Then
      MsgBox ("No objects found on Layer 'Layer01'")
   Else
      Dim tEnt As AcadEntity
      For Each tEnt In tSelSet
         tEnt.Highlight (True)
      Next
   End If
End Sub

Private Function getSelSetByLayer(ByVal LayerName As String) As AcadSelectionSet
   Dim tRetVal As AcadSelectionSet
   On Error Resume Next
   'create selectionset
   Set tRetVal = ThisDrawing.SelectionSets.Add("mySelSet")
   If tRetVal Is Nothing Then Set tRetVal = ThisDrawing.SelectionSets.Item("mySelSet")
   'create filter for selection
   Dim tDxfCodes(0) As Integer: tDxfCodes(0) = 8     '8=dxfcode for "layername"
   Dim tDxfValues(0) As Variant: tDxfValues(0) = LayerName
   'select
   tRetVal.Clear
   Call tRetVal.Select(acSelectionSetAll, , , tDxfCodes, tDxfValues)
   'return
   Set getSelSetByLayer = tRetVal
End Function

 

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 „Gefällt mir“-Angaben
Nachricht 3 von 8

Anonymous
Nicht anwendbar

Thank you Alfred, but it only works with layer01 not with layer02. Smiley (traurig)

 

I tried: Set tSelSet = getSelSetByLayer("Layer01", "layer02") but it returned with an error:

"Wrong number of arguments or invalid property assignement."

I forgot something?

 

gr. László

0 „Gefällt mir“-Angaben
Nachricht 4 von 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

you can define the layername-filter in one of the following modes:

  • using a comma as separator to define multiple distinct layernames (be careful, don't write a space after the comma)
  • using wildchars like "?" or "*"

 

HTH, - alfred -

 

Samples:

Set tSelSet = getSelSetByLayer("Layer01,Layer02")
Set tSelSet = getSelSetByLayer("Layer0?")
Set tSelSet = getSelSetByLayer("Layer??")
Set tSelSet = getSelSetByLayer("Layer*")
------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Nachricht 5 von 8

Anonymous
Nicht anwendbar

Thank you again Alfred!

It works great.

I learned a lot from it.

 

gr. LaszloSmiley (überglücklich)

0 „Gefällt mir“-Angaben
Nachricht 6 von 8

Anonymous
Nicht anwendbar

This code works fine.

Now I wants a different layer zb. layer03 to be highlight (false). How to combine this in the same code?

 

gr. Laszlo

Public Sub HighlightTest()
   Dim tSelSet As AcadSelectionSet
   Set tSelSet = getSelSetByLayer("Layer01")
   If tSelSet Is Nothing Then
      MsgBox ("No Selectionset")
   ElseIf tSelSet.Count = 0 Then
      MsgBox ("No objects found on Layer 'Layer01'")
   Else
      Dim tEnt As AcadEntity
      For Each tEnt In tSelSet
         tEnt.Highlight (True)
      Next
   End If
End Sub

Private Function getSelSetByLayer(ByVal LayerName As String) As AcadSelectionSet
   Dim tRetVal As AcadSelectionSet
   On Error Resume Next
   'create selectionset
   Set tRetVal = ThisDrawing.SelectionSets.Add("mySelSet")
   If tRetVal Is Nothing Then Set tRetVal = ThisDrawing.SelectionSets.Item("mySelSet")
   'create filter for selection
   Dim tDxfCodes(0) As Integer: tDxfCodes(0) = 8     '8=dxfcode for "layername"
   Dim tDxfValues(0) As Variant: tDxfValues(0) = LayerName
   'select
   tRetVal.Clear
   Call tRetVal.Select(acSelectionSetAll, , , tDxfCodes, tDxfValues)
   'return
   Set getSelSetByLayer = tRetVal
End Function

 

0 „Gefällt mir“-Angaben
Nachricht 7 von 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

Public Sub HighlightTest()
   Dim tSelSet As AcadSelectionSet
   Set tSelSet = getSelSetByLayer("Layer01,Layer02,Layer03")
   If tSelSet Is Nothing Then
      MsgBox ("No Selectionset")
   ElseIf tSelSet.Count = 0 Then
      MsgBox ("No objects found on Layer 'Layer01/02/02'")
   Else
      Dim tEnt As AcadEntity
      For Each tEnt In tSelSet
         Select case ucase(tEnt.Layer)
            case "LAYER01","LAYER02"
               tEnt.Highlight (True)
            case "LAYER03"
               tEnt.Highlight (false)
         End Select
      Next
   End If
End Sub

 

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Nachricht 8 von 8

Anonymous
Nicht anwendbar
Akzeptierte Lösung

It's simplier than I thought.

Thanks!

 

gr. Laszlo

0 „Gefällt mir“-Angaben