Delete Selection Set

Delete Selection Set

Anonymous
Not applicable
675 Views
13 Replies
Message 1 of 14

Delete Selection Set

Anonymous
Not applicable
I am in the process of learning Visual Basic. A particular routine that I am working on creates a selection set. When I rerun the routine within the same drawing I get an error saying that the "selection set already exists". What is the best way to delete the old selection set?

Thanks,
Will Massie
Sause Brothers
0 Likes
676 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
This is the way that I do it.

Joe
--
On Error Resume Next
oSS("Inserts").Delete
Set oSS = ThisDrawing.SelectionSets.Add("Inserts")
0 Likes
Message 3 of 14

Anonymous
Not applicable
Thanks to the fine folks at
VBDesign.Net.


 

This is how I get rid of mine:


size=2>''****************************************************************

Public Function vbdPowerSet(strName
color=#000080>As String
) As AcadSelectionSet
 
color=#000080>Dim
objSelSet As
AcadSelectionSet
  Dim objSelCol As
AcadSelectionSets
  Set objSelCol =
ThisDrawing.SelectionSets
   For Each
objSelSet In
objSelCol
      If
objSelSet.Name = strName
color=#000080>Then

       
objSelCol.Item(strName).Delete
       
Exit For
     
color=#000080>End If

  
Next

  Set objSel
color=#000080>Set
= objSelCol.Add(strName)
 
color=#000080>Set
vbdPowerSet =
objSelSet
End Function


size=2>''****************************************************************

joseguia


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Will Massie asked:

:When I rerun the routine within the same drawing I get an error

saying that the "selection set already exists". What is the best

way to delete the old selection set?


size=2>


 
0 Likes
Message 4 of 14

Anonymous
Not applicable
There's no need to loop through every selection set when you can simply
access it by name:

Set ss = ThisDrawing.SelectionSets()

A simple error trap will catch the exception that's thrown if the set
doesn't exist. For the least amount of code required to get the job done,
Joe's approach wins. For the *most* amount of code required to get the job
done, vbdPowerSet gets the blue ribbon.

--
"If you want to be somebody else change your mind"
http://www.acadx.com
http://vbxtender.sourceforge.net
0 Likes
Message 5 of 14

Anonymous
Not applicable
Hmm this is probably true, but I pop this badboy
into a module and ever since I started VBA i have
yet to worry about error trapping for a SelectionSet.

Why is that. because all my selections sets for every
bit code are called out as:
Set ssetObj = vbdPowerSet("mySelectionSet")
-
as I heard in an info-mercial once
"Set it and forget it" 🙂

no selectionset worrying-jose

"Frank Oquendo" wrote in message
news:D0CAA8A155E901BDEF33CF07A80E53DF@in.WebX.maYIadrTaRb...
> There's no need to loop through every selection set when you can simply
> access it by name:
>
> Set ss = ThisDrawing.SelectionSets()
>
> A simple error trap will catch the exception that's thrown if the set
> doesn't exist. For the least amount of code required to get the job done,
> Joe's approach wins. For the *most* amount of code required to get the job
> done, vbdPowerSet gets the blue ribbon.
>
> --
> "If you want to be somebody else change your mind"
> http://www.acadx.com
> http://vbxtender.sourceforge.net
>
>
0 Likes
Message 6 of 14

Anonymous
Not applicable
Jose Guia had this to say:

> as I heard in an info-mercial once
> "Set it and forget it" 🙂

Convenience is no reason for using sloppy code. Here, let me help:

Public Function CreateSelectionSet(ssName As String) As AcadSelectionSet

On Error Resume Next
ThisDrawing.SelectionSets(ssName).Delete
Set CreateSelectionSet = ThisDrawing.SelectionSets.Add(ssName)

End Function

--
"If you want to be somebody else change your mind"
http://www.acadx.com
http://vbxtender.sourceforge.net
0 Likes
Message 7 of 14

Anonymous
Not applicable
I cannot think of a good reason why you would do it this way. OK, so you want a function. Here you go . . .

Public Function vbdPowerSet(Name As String, oSS As AcadSelectionSet) As Boolean
On Error Resume Next
With ThisDrawing
.SelectionSets(Name).Delete
Set oSS = .SelectionSets.Add(Name)
End With
If Not oSS Is Nothing Then vbdPowerSet = True
End Function

Public Sub Start()
Dim ss As AcadSelectionSet
If vbdPowerSet("SS", ss) Then
MsgBox "Selection Set created"

Else
MsgBox "Oh no, something when wrong"
End If
End Sub

Does the same thing, much faster.

Joe
--
0 Likes
Message 8 of 14

Anonymous
Not applicable
 

Ok, so both you guys are right.

 

Frank and Joe.

 

I've only been doing this for about a year
and

found the vbdesign.net function and
have

used it ever since.

 

either way works.

 

 
0 Likes
Message 9 of 14

Anonymous
Not applicable
Randall is right too, it's just that IMHO you do not need to go through all those gyrations that his code does to acheive the same results.

Joe
--
0 Likes
Message 10 of 14

Anonymous
Not applicable
Absolutely correct on all counts, Joe.

--
"If you want to be somebody else change your mind"
http://www.acadx.com
http://vbxtender.sourceforge.net
0 Likes
Message 11 of 14

Anonymous
Not applicable
Thanks for both your help, I do believe I will
change my evil ways now that I have seen the light.

 

it does show to do a weebit faster doing it the
y'alls way.

 

thanks,

 

bye


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Randall
is right too, it's just that IMHO you do not need to go through all those
gyrations that his code does to acheive the same results.

Joe
--

0 Likes
Message 12 of 14

Anonymous
Not applicable
I've been having trouble with the code for deleting a selection set
if it exists:

'Delete the Selection Set GlyphIDs if it Exists
If Not IsNull(ThisDrawing.SelectionSets.Item("GlyphIDs")) Then
Set setGlyphIDs = ThisDrawing.SelectionSets.Item("GlyphIDs")
setGlyphIDs.Delete
End If

Doesn't run unless the selection set already exists.

David William Edwards
www.tcfonts.com
Font Services: Creation, Customization & Conversion
Fontasm! Truetype to AutoCAD SHX Font/Arc-Based DXF Converter
0 Likes
Message 13 of 14

Anonymous
Not applicable
David William Edwards wrote:

> Doesn't run unless the selection set already exists.

Isn't that what the code is designed to do? Even so, try this:

http://code.acadx.com/visualbasic/010.htm

--
Someone left the grass out in the yard all night
http://www.acadx.com
0 Likes
Message 14 of 14

Anonymous
Not applicable
On Error Resume Next
ThisDrawing.SelectionSets("GlyphIDs").Delete
Err.Clear


"David William Edwards" wrote in message news:BD4F1C0FD5FE87C41473185E1B35BEDD@in.WebX.maYIadrTaRb...
> I've been having trouble with the code for deleting a selection set
> if it exists:
>
> 'Delete the Selection Set GlyphIDs if it Exists
> If Not IsNull(ThisDrawing.SelectionSets.Item("GlyphIDs")) Then
> Set setGlyphIDs = ThisDrawing.SelectionSets.Item("GlyphIDs")
> setGlyphIDs.Delete
> End If
>
> Doesn't run unless the selection set already exists.
>
> David William Edwards
> www.tcfonts.com
> Font Services: Creation, Customization & Conversion
> Fontasm! Truetype to AutoCAD SHX Font/Arc-Based DXF Converter
>
>
0 Likes