View Full Version : Erasing a selection set name
Coolmo
2004-08-25, 02:46 PM
Here's a quicky. How do you release or erase a selection set once it is created? I want to use:
Set sset = ThisDrawing.SelectionSets.Add("ss1")
where ss1 is the name of the selection set but after the objects are used I want the user to be able to select another selection set with the same name to keep working but an error keeps coming up stating the selection set (ss1) already exists. Help!
warren.medernach
2004-08-25, 02:50 PM
Hi williams.60073.
When you are done with the selectionset just call:
sset.Delete
Or, if you've lost the reference to sset call:
ThisDrawing.Selectionsets("ss1").Delete
Hope this helps
Warren M
Coolmo
2004-08-25, 02:58 PM
The help file suggests that everything in the selection set will also be deleted if I do that. Is that true?
From the help file:
"The Delete method deletes a selection set and all items in the selection set. Neither the selection set, nor the items previously in the selection set will exist after a call to the Delete method."
Ed Jobe
2004-08-25, 03:20 PM
You don't have to worry about getting rid of ss's, they're only temporary in the dwg. When you close the dwg, the ss collection is cleared. All you have to worry about is when creating a new one, you don't try to use a name that already exists or you'll get an error. The usual method of avoiding runtime errors is to error trap. Try to create the set with the name you want. If it errors, reuse the name.
Public Function AddSelectionSet1(SetName As String) As AcadSelectionSet
' This routine does the error trapping neccessary for creating selection sets.
On Error Resume Next
Set AddSelectionSet = ThisDrawing.SelectionSets.Add(SetName)
If Err.Number <> 0 Then
Set AddSelectionSet = ThisDrawing.SelectionSets.Item(SetName)
End If
End Function
Once you have the ss, use ss.Clear to start fresh.
warren.medernach
2004-08-25, 07:16 PM
From the AutoCAD ActiveX and VBA Reference for 2005:
"Delete: The Delete method deletes a selection set object, but not the objects in the selection set. While the selection set itself will not exist after the call to the Delete method, the items previously in the selection set will still exist. "
Warren M
The help file suggests that everything in the selection set will also be deleted if I do that. Is that true?
From the help file:
"The Delete method deletes a selection set and all items in the selection set. Neither the selection set, nor the items previously in the selection set will exist after a call to the Delete method."
inner69923
2004-08-25, 09:41 PM
You don't have to worry about getting rid of ss's, they're only temporary in the dwg. When you close the dwg, the ss collection is cleared. All you have to worry about is when creating a new one, you don't try to use a name that already exists or you'll get an error. The usual method of avoiding runtime errors is to error trap. Try to create the set with the name you want. If it errors, reuse the name.
Public Function AddSelectionSet1(SetName As String) As AcadSelectionSet
' This routine does the error trapping neccessary for creating selection sets.
On Error Resume Next
Set AddSelectionSet = ThisDrawing.SelectionSets.Add(SetName)
If Err.Number <> 0 Then
Set AddSelectionSet = ThisDrawing.SelectionSets.Item(SetName)
End If
End Function
Once you have the ss, use ss.Clear to start fresh.
nice, better than what i used to clean before create
Public Sub limpiadibu(x As Variant)
Dim TestForSelSet As AcadSelectionSets
Dim Cntr As Long
Set TestForSelSet = AutoCAD.Application.ActiveDocument.SelectionSets
If AutoCAD.Application.ActiveDocument.SelectionSets.Count > 0 Then
For Cntr = 0 To AutoCAD.Application.ActiveDocument.SelectionSets.Count - 1
If TestForSelSet(Cntr).Name = "SS2" Then
AutoCAD.Application.ActiveDocument.SelectionSets.Item("SS2").Delete
End If
Next Cntr
End If
End Sub
Ed Jobe
2004-08-25, 10:31 PM
Even if you were going that route, remember that ss's are in a collection and you can ForEach those.
Function AddSelectionSet (name As String) As AcadSelectionSet
Dim ss As AcadSelectionSet
For Each ss In ThisDrawing.AcadSelectionSets
If ss.Name = name Then
ss.Clear
Set AddSelectionSet = ss
Else
Set AddSelectionSet = ThisDrawing.SelectionSets.Add name
End If
End Function
Ed Jobe
2004-08-25, 10:34 PM
Forget that, that's going to try and add an ss for each ss in the collection. It will error the next loop. But I just wanted to show you how to iterate with For Each.
You don't have to worry about getting rid of ss's, they're only temporary in the dwg. When you close the dwg, the ss collection is cleared.
What about this statement from the documentation?
Attempting to manage a large number of selection sets simultaneously is not recommended. An AutoLISP application cannot have more than 128 selection sets open at once. (The limit may be lower on your system.) When the limit is reached, AutoCAD refuses to create more selection sets. Keep a minimum number of sets open at a time, and set unneeded selection sets to nil as soon as possible. If the maximum number of selection sets is reached, you must call the gc function to free unused memory before another ssget will work.
Coolmo
2004-08-26, 08:20 PM
What about this statement from the documentation?
I guess that is talking about in the current open drawing. As soon as another is opened the selection set count is reset.
From the help file:
"The Delete method deletes a selection set and all items in the selection set. Neither the selection set, nor the items previously in the selection set will exist after a call to the Delete method."
Also, my documentation about deleting the entities in the selection set came from an old help file. I guess they changed that feature after Acad 14?
Ed Jobe
2004-08-26, 09:17 PM
What I meant about "you don't have to worry" is demonstrated using the method I presented, if you try to create a ss and it already exists, use it instead of deleting it and creating a new one with the same name. The ss count doesn't increment.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.