Problem with SelectionSets

Problem with SelectionSets

Anonymous
Not applicable
459 Views
10 Replies
Message 1 of 11

Problem with SelectionSets

Anonymous
Not applicable
Hi,
the code of my procedure is:
Public Function GetLayerEnts(sLayrName As String) As AcadSelectionSet
Dim iType(0) As Integer
Dim vData(0) As Variant
Dim sSet As AcadSelectionSet
On Error Resume Next
Set sSet = MyDrawing.SelectionSets("sel" & sLayrName)
If err Then Set sSet = MyDrawing.SelectionSets.Add("sel" & sLayrName)
sSet.Clear

iType(0) = 8
vData(0) = sLayrName
sSet.Select acSelectionSetAll, FilterType:=iType, FilterData:=vData
If Not sSet Is Nothing Then
Set GetLayerEnts = sSet
End If
End Function

I call this procedure more than 60 times(one for each layer of my drawing) and there is one momment in which Sset returns Nothing despite there should be entities in the selection set. I don't know why this is happenning.

Please, can anybody help me?? it's driving me crazy.
0 Likes
460 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Give this a try ...

Public Function GetLayerEnts(sLayrName As String) As AcadSelectionSet
Dim iType(0) As Integer
Dim vData(0) As Variant
Dim LayerName As String
Dim sSet As AcadSelectionSet

On Error Resume Next

LayerName = "sel" & sLayrName
ThisDrawing.SelectionSets(LayerName).Delete
Set sSet = ThisDrawing.SelectionSets.Add(LayerName)

iType(0) = 8
vData(0) = LayerName
sSet.Select acSelectionSetAll, FilterType:=iType, FilterData:=vData

If sSet.Count Then
Set GetLayerEnts = sSet
End If
End Function

Public Sub Test()
Dim oLayer As AcadLayer
Dim oSS As AcadSelectionSet

For Each oLayer In ThisDrawing.Layers
Set oSS = GetLayerEnts(oLayer.Name)
If Not oSS Is Nothing Then
MsgBox oLayer.Name & " Count: " & oSS.Count
Else
MsgBox oLayer.Name & " Count: 0"
End If
Next oLayer
End Sub

Joe
--
wrote in message news:5196604@discussion.autodesk.com...
Hi,
the code of my procedure is:
Public Function GetLayerEnts(sLayrName As String) As AcadSelectionSet
Dim iType(0) As Integer
Dim vData(0) As Variant
Dim sSet As AcadSelectionSet
On Error Resume Next
Set sSet = MyDrawing.SelectionSets("sel" & sLayrName)
If err Then Set sSet = MyDrawing.SelectionSets.Add("sel" & sLayrName)
sSet.Clear

iType(0) = 8
vData(0) = sLayrName
sSet.Select acSelectionSetAll, FilterType:=iType, FilterData:=vData
If Not sSet Is Nothing Then
Set GetLayerEnts = sSet
End If
End Function

I call this procedure more than 60 times(one for each layer of my drawing)
and there is one momment in which Sset returns Nothing despite there should
be entities in the selection set. I don't know why this is happenning.

Please, can anybody help me?? it's driving me crazy.
0 Likes
Message 3 of 11

Anonymous
Not applicable
it's the same...
the problem is, I don't know why, that
Set sSet = ThisDrawing.SelectionSets.Add(LayerName)
returns sset=nothing though my drawing has entities in the layer in which is trying to get the selectionset.
It happens after an undetermined number of selections... I have read in other post that acad only allows 120 selectionsets, but I think that if I destroy de object after each processed layer, that shouldn't be the problem.

Thank very much you for you reply anyway.
0 Likes
Message 4 of 11

Anonymous
Not applicable
In your original code you are not destroying the named selection set like I
am in my code.

Did you try my code on your drawing?

Can you send me the drawing directly [don't post on newsgroup]?

Joe
--

wrote in message news:5196698@discussion.autodesk.com...
it's the same...
the problem is, I don't know why, that
Set sSet = ThisDrawing.SelectionSets.Add(LayerName)
returns sset=nothing though my drawing has entities in the layer in which is
trying to get the selectionset.
It happens after an undetermined number of selections... I have read in
other post that acad only allows 120 selectionsets, but I think that if I
destroy de object after each processed layer, that shouldn't be the problem.

Thank very much you for you reply anyway.
0 Likes
Message 5 of 11

mdhutchinson
Advisor
Advisor
Joe... I am one of perhaps many that have gained good help from your book and from you directly as well ... at one point you had said that you'd be willing to help (of course on a limited bases)... How can I find your email address?
0 Likes
Message 6 of 11

Anonymous
Not applicable
If you are using Outlook Express as a reader then reply to sender would give
you that info or

joesutphin@earthlink.net


wrote in message news:5196848@discussion.autodesk.com...
Joe... I am one of perhaps many that have gained good help from your book
and from you directly as well ... at one point you had said that you'd be
willing to help (of course on a limited bases)... How can I find your email
address?
0 Likes
Message 7 of 11

Anonymous
Not applicable
Setting the SSet variable to nothing does not "delete" the selectionset, but removes a reference to it.

Before setting the variable to nothing, do the .Delete method is it. This will delete the selection set (considering that the 120 selectionset max is you problem)....
0 Likes
Message 8 of 11

Anonymous
Not applicable
Try this one. works for me nice

Option Explicit

Public Function GetLayerEnts(ByVal sLayrName As String) As AcadSelectionSet
Dim iType(0) As Integer
Dim vData(0) As Variant
Dim LayerName As String
Dim sSet As AcadSelectionSet

On Error Resume Next

LayerName = sLayrName ''=>problem was here

For Each sSet In ThisDrawing.SelectionSets
If sSet.Name = LayerName Then
sSet.Delete
Set sSet = Nothing
Exit For
End If
Next sSet

Set sSet = ThisDrawing.SelectionSets.Add(LayerName)


iType(0) = 8
vData(0) = LayerName
sSet.Select acSelectionSetAll, , , iType, vData

If sSet.Count > 0 Then
Set GetLayerEnts = sSet
End If

End Function
''test part by Joe Sutphin
Public Sub Test()
Dim oLayer As AcadLayer
Dim oSS As AcadSelectionSet
Dim iCount As Integer

For Each oLayer In ThisDrawing.Layers
Set oSS = GetLayerEnts(oLayer.Name)

If Not oSS Is Nothing Then
iCount = oSS.Count
MsgBox oLayer.Name & " Count: " & iCount
Else
MsgBox oLayer.Name & " Count: 0"
End If
Next oLayer
End Sub

Fatty

~'J'~
0 Likes
Message 9 of 11

Anonymous
Not applicable
Note all the examples here use On Error Resume Next without a corresponding On Error GoTo 0 statement. It is good practice to stop Error Trapping with the On Error GoTo 0 statement straight after the code you expect may error.

Regards - Nathan
0 Likes
Message 10 of 11

Anonymous
Not applicable
I thought I would add my approach to the mix.

I have a function that creates the next available selectionset based upon a naming convention of "SSET" and a incremented number.

I create the selection set using this function and then delete it as soon as I am finished with it.

Public Function CreateEmptySSet() As AcadSelectionSet
Dim blnExists As Boolean
Dim intCount As Integer
Dim strName As String
Dim objSSet As AcadSelectionSet
blnExists = True
intCount = 0
Do Until blnExists = False
blnExists = False
intCount = intCount + 1
strName = "SSET" & intCount
For Each objSSet In ThisDrawing.SelectionSets
If UCase(objSSet.Name) = strName Then blnExists = True
Next objSSet
Loop
Set CreateEmptySSet = ThisDrawing.SelectionSets.Add(strName)
End Function

Regards - Nathan
0 Likes
Message 11 of 11

Anonymous
Not applicable
excelent point Nathan, thnks!

wrote in message news:5197802@discussion.autodesk.com...
Note all the examples here use On Error Resume Next without a corresponding
On Error GoTo 0 statement. It is good practice to stop Error Trapping with
the On Error GoTo 0 statement straight after the code you expect may error.

Regards - Nathan
0 Likes