Delete all named selection sets

Delete all named selection sets

mdhutchinson
Advisor Advisor
755 Views
7 Replies
Message 1 of 8

Delete all named selection sets

mdhutchinson
Advisor
Advisor
How can I delete all named selection sets from a drawing?
I tried a simple interation thru the collection to do it and I crashed AutoCAD.
0 Likes
756 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Have you tried

If ThisDrawing.SelectionSets.Count > 0 Then
While ThisDrawing.SelectionSets.Count > 0
ThisDrawing.SelectionSets.Item(ThisDrawing.SelectionSets.Count - 1).Delete
Wend
End If
0 Likes
Message 3 of 8

mdhutchinson
Advisor
Advisor
I am currently using:
[code]
Dim ssSelSets As AcadSelectionSets
Dim ssSelSet As AcadSelectionSet
Dim i As Integer
For i = (ssSelSets.Count - 1) To 0 Step -1
Set ssSelSet = Application.ActiveDocument.SelectionSets(i)
ssSelSet.Delete
Next i
'===============
But it looks yours is better. I tweeked it a bit:

While ThisDrawing.SelectionSets.Count > 0
ThisDrawing.SelectionSets.Item(0).Delete
Wend
[/code]
many thanks!
0 Likes
Message 4 of 8

mdhutchinson
Advisor
Advisor
okay... next question:

It seems that I can:

Set MySelSet = Nothing
but the selection set can still be retrieved via the name property?... is this correct?
... although
If I delete the selection set of a given name... the variable is destroyed... correct?
0 Likes
Message 5 of 8

Anonymous
Not applicable
I am not a pro, so take this with a grain of salt. When you set your variable to nothing, e.g. Set MySelSet = Nothing, you are just removing the pointer to the selectionset object, it still exist in the selectionset collection. However, when you delete the object, the variable has nothing to point to, so it is not available.
0 Likes
Message 6 of 8

Anonymous
Not applicable
it depends on the nature of the object you are pointing to.
an object may have many variables pointing on it, and there is a counter of them. when last variable pointing to object is removed [either by going out of the scope or changing value fe setting to nothing], the runtime sends request to object to delete himself [each object has some kind of constructor and destructor methods]. now, it depends on the object should it accept request for self-deleting or not. usualy such non-self-deleting objects have special "delete" method that you must separately call to delete such object
0 Likes
Message 7 of 8

Anonymous
Not applicable
You deserve a medal for this sub routine.

THANK YOU!!!
0 Likes
Message 8 of 8

Anonymous
Not applicable
I use the similar one

Dim oSset As AcadSelectionSet
With ThisDrawing.SelectionSets
While .Count > 0
.Item(0).Delete
Wend
Set oSset = .Add("NewOne")
End With

~'J'~
0 Likes