Add line to selection set

Add line to selection set

Anonymous
Not applicable
3,312 Views
4 Replies
Message 1 of 5

Add line to selection set

Anonymous
Not applicable

Hello,

 

how could I add a drawn line directly to an existing selection set?

 

In my example there is a layer based selection set called "SSetM" with 60 elements. Now I set up a line by "Set Linie1 = ZielDxf.ModelSpace.AddLine(pt1,pt2)" and want to add it to the existing selection set by "SSetM.AddItems (Linie1)".

 

What is the rigth way to do this?

 

Thanks in advance!

 

Lars

0 Likes
Accepted solutions (1)
3,313 Views
4 Replies
Replies (4)
Message 2 of 5

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

>> want to add it to the existing selection set

The parameter for AddItems is an array, not a single object.

So you have to create an array, add your object to that array and then add this array to your selectionset.

 

Public Sub test()
   
   'create the line
   Dim tLine As AcadLine
   Dim tPnt1(0 To 2) As Double
   Dim tPnt2(0 To 2) As Double: tPnt2(1) = 5.9
   Set tLine = ThisDrawing.ModelSpace.AddLine(tPnt1, tPnt2)
   
   'create the selectionset
   Dim tSelSet As AcadSelectionSet
   On Error Resume Next
   Set tSelSet = ThisDrawing.SelectionSets.Add("XX")
   If tSelSet Is Nothing Then
      Set tSelSet = ThisDrawing.SelectionSets.Item("XX")
      tSelSet.Clear
   End If
   
   'add the line to an array
   Dim tArr(0) As AcadEntity
   Set tArr(0) = tLine
   
   'add the array of object to the selection-set
   tSelSet.AddItems (tArr)
   
   Call MsgBox("Entities in SelectionSet: " & CStr(tSelSet.Count))
End Sub

 

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 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks, Alfred.

 

I thought that I've tried it this way...anyway this time it works.

0 Likes
Message 4 of 5

Anonymous
Not applicable
You could also try just using

SSetM.Select acSelectionSetLast

Right after the AddLine() statement
0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks a ot for the hint. This way it works as well.

0 Likes