Recognizing existence of a selectionset

Recognizing existence of a selectionset

Anonymous
Not applicable
493 Views
5 Replies
Message 1 of 6

Recognizing existence of a selectionset

Anonymous
Not applicable
How can I detect if a selectionset with a special name exist.
I want to run the commands:

Dim sset As AcadSelectionSet
Set sset = ThisDrawing.SelectionSets.Add("SS1")

but maybe,for some reason the selectionset with name "SS1" already exist in the drawing, therefore an error occurs.
any help is appreciated
0 Likes
494 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Now I know:

If ThisDrawing.SelectionSets.Count = 0 Then
Set sset = ThisDrawing.SelectionSets.Add("SS1")
Else
On Error Resume Next
ThisDrawing.SelectionSets.Item("SS1").Delete
On Error GoTo 0
Set sset = ThisDrawing.SelectionSets.Add("SS1")
End If
0 Likes
Message 3 of 6

Anonymous
Not applicable
That might work, but not always...try:

'going to check for existence of selection set, if it doesn't exist it will
throw an error...trap it
On Error Resume Next

'check for the sel set
Dim selset As AcadSelectionSet
Set selset = ThisDrawing.SelectionSets.Item("SS1")

'if it exists clear it, if not make it
If Not selset Is Nothing Then
selset.Clear
Else
Set selset = ThisDrawing.SelectionSets.Add("SS1")
End If

Matt
0 Likes
Message 4 of 6

Anonymous
Not applicable
Thank Matt for your nice solution. I tried it and it did work. but why do you think my codes may not always work?
0 Likes
Message 5 of 6

Anonymous
Not applicable
Now that I re-read youe post it may work every time.

The more I think about it the more I'm pretty sure yours is as good as mine.

Ignore my post 🙂



wrote in message news:5863764@discussion.autodesk.com...
Thank Matt for your nice solution. I tried it and it did work. but why do
you think my codes may not always work?
0 Likes
Message 6 of 6

Anonymous
Not applicable
another good approach:

Dim sset As AcadSelectionSet
For Each sset In ThisDrawing.SelectionSets
If sset .Name = "SS1" Then
ThisDrawing.SelectionSets("SS1").Delete
Exit For
End If
Next
ThisDrawing.SelectionSets.Add ("SS1")
0 Likes