How to refer to single Item (object) contain in SelectionSet ?

How to refer to single Item (object) contain in SelectionSet ?

l_dabrowskiUZAN4
Contributor Contributor
496 Views
2 Replies
Message 1 of 3

How to refer to single Item (object) contain in SelectionSet ?

l_dabrowskiUZAN4
Contributor
Contributor

Hi;

I want to create a SelectionSet "SS1" and select only Polyline on the screen. Then I want to be able to connect to the specified polyline. How to do it ? I indicate the name SelectionSet "SS1" and the Item position, in this case Item 1. I need to get to Polyline and pull out the Handle property and the Lenght property. I don't know why it doesn't work, please help...

 

Sub Example_SelectOnScreen()
    ' This example adds objects to a selection set by prompting the user
    ' to select ones to add.
    
    Dim ssetObj As AcadSelectionSet
    Dim oPolyline As Variant
    Dim Lenght As String
    Dim Handle As String
    
    
    AppActivate ThisDrawing.Application.Caption
    
    
    ' Create the selection set
    Set ssetObj = ThisDrawing.SelectionSets.Add("SS1")
       
    ' Add objects to a selection set by prompting user to select on the screen
    ssetObj.SelectOnScreen
    
    ssetObj.Highlight True
    MsgBox ssetObj.Name
    ssetObj.Highlight False
    
    Set oPolyline = ThisDrawing.SelectionSets("SS1").Item(1)
    Lenght = oPolyline.Lenght
    Handle = oPolyline.Handle
    
    MsgBox "Lenght is: " & Lenght
    MsgBox "Handle is: " & Handle
    
    ThisDrawing.SelectionSets("SS1").Delete
    
End Sub

 Error_Index.jpgLocals.jpgLine.jpg

0 Likes
Accepted solutions (1)
497 Views
2 Replies
Replies (2)
Message 2 of 3

Ed__Jobe
Mentor
Mentor
Accepted solution

Collections indices are zero based, i.e. the first element is 0, not 1. Also, Length is misspelled as 'lenght'.

 

Your code doesn't account for the possibility that the selection set might already exist. You can use the functions below to do error trapping.

 

 

'Your code
    Dim oPolyLine As AcadLWPolyline  'by using a ss filter, you can cast this var as the correct type
    ' Create the selection set
    Set ss = GetSS_PLineFilter()
    Set oPolyLine = ss.(0)
    With oPolyLine
      lenght = .Length  'Your language might spell it ht, but the API uses th
      h = .Handle       'don't use variable names that are the same as a property or type name
    End With
       

Public Function AddSelectionSet(SetName As String) As AcadSelectionSet
' This routine does the error trapping neccessary for when you want to create a
' selectin set. It takes the proposed name and either adds it to the selectionsets
' collection or sets it.
    On Error Resume Next
    Set AddSelectionSet = ThisDrawing.SelectionSets.Add(SetName)
    If Err.Number <> 0 Then
        Set AddSelectionSet = ThisDrawing.SelectionSets.Item(SetName)
        AddSelectionSet.Clear
    End If
End Function

Public Function GetSS_PLineFilter() As AcadSelectionSet
    'creates an ss of Text only
    Dim s1 As AcadSelectionSet      'for filtered ss
        
        'filter is needed if there's no pfss
        Dim intFtyp(0) As Integer                       ' setup for the filter
        Dim varFval(0) As Variant
        Dim varFilter1, varFilter2 As Variant
        intFtyp(0) = 0: varFval(0) = "LWPOLYLINE"       ' get only text and mtext
        varFilter1 = intFtyp: varFilter2 = varFval
        Set s1 = AddSelectionSet("ssPLineFilter")        ' create or get the set
        s1.Clear                                        ' clear the set
        s1.Select acSelectionSetAll, , , varFilter1, varFilter2      ' do it
    
    Set GetSS_PLineFilter = s1

End Function

 

 

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 3

l_dabrowskiUZAN4
Contributor
Contributor

Generally, I know that arrays start with index 0, but I was confused by the description: "Item1". I will remember about this. Thank you for your help and two good functions that will allow me to write a SelectionSet procedure at a higher level.

0 Likes