Efficient code, selection set filter/RemoveItem from array

Efficient code, selection set filter/RemoveItem from array

Anonymous
Not applicable
557 Views
6 Replies
Message 1 of 7

Efficient code, selection set filter/RemoveItem from array

Anonymous
Not applicable
Hi,

Quick query.....

I can create selection set based on a block name, what is the most efficient way to filter out blocks with a specfic tag value?

At the point of selection set creation?
Or by using RemoveItem from an array?

Many thanks,

Dom
0 Likes
558 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
You cannot filter for Attribute values in a SS. So you must use the second
option.....

wrote in message news:[email protected]...
At the point of selection set creation?
Or by using RemoveItem from an array?
0 Likes
Message 3 of 7

Anonymous
Not applicable
Thanks for the reply,

I thought that would probably be the case...struggling a bit with RemoveItem...

So I have a Selection set of all blocks named "myblock". To filter out those with a particular tag value............

a bit of code so far........

Dim objSS As AcadSelectionSet
Dim i As Integer
Set objSS = sset(Array(0, 2), Array("Insert", "RoomData"))
'''get a count of full selectionset
MsgBox objSS.Count

Dim blkRef As AcadBlockReference
Dim vAttribs As Variant
Dim vAttrib As Variant
For Each blkRef In objSS
vAttribs = blkRef.getattributes
For Each vAttrib In vAttribs
If vAttrib.TagString = "tagname" And vAttrib.TextString = "specifictagvalue" Then
'''this is where I'm struggling as I'm aware that I can't RemoveItem from objSS
'''I believe I need to somehow use an entity array?!

Would really appreciate a pointer in the right direction!

Many thanks,

Dom
0 Likes
Message 4 of 7

Anonymous
Not applicable
Try something like this:
[code]
Function RemoveItemsFromSS(objSS As AcadSelectionSet) As AcadSelectionSet
Dim blkRef As AcadBlockReference
Dim vAttribs As Variant
Dim vAttrib As Variant
Dim oRemItems() As AcadEntity
Dim oEnt As AcadEntity
Dim I As Long

ReDim oRemItems(0 To objSS.Count) 'Make sure it's large enough to hold the
items
For Each oEnt In objSS
If TypeOf oEnt Is AcadBlockReference Then
Set blkRef = oEnt
If blkRef.HasAttributes = True Then
vAttribs = blkRef.GetAttributes
For Each vAttrib In vAttribs
If vAttrib.TagString = "tagname" And _
vAttrib.TextString = "specifictagvalue" Then
Set oRemItems(I) = blkRef
I = 1 + I
Exit For
End If
Next
End If
End If
Next
ReDim Preserve oRemItems(0 To I - 1)
objSS.RemoveItems oRemItems

Set RemoveItemsFromSS = objSS

End Function
[/code]

wrote in message news:[email protected]...
Thanks for the reply,

I thought that would probably be the case...struggling a bit with
RemoveItem...

So I have a Selection set of all blocks named "myblock". To filter out those
with a particular tag value............

a bit of code so far........
0 Likes
Message 5 of 7

Anonymous
Not applicable
Brilliant!

thats helped me no end

thanks,

dom
0 Likes
Message 6 of 7

Anonymous
Not applicable
Hi Jeff,
Why create a separate array? Doesn't the selection set
have a removeitems method?


"Jeff Mishler" wrote in message
news:[email protected]...
Try something like this:
[code]
Function RemoveItemsFromSS(objSS As AcadSelectionSet) As AcadSelectionSet
Dim blkRef As AcadBlockReference
Dim vAttribs As Variant
Dim vAttrib As Variant
Dim oRemItems() As AcadEntity
Dim oEnt As AcadEntity
Dim I As Long

ReDim oRemItems(0 To objSS.Count) 'Make sure it's large enough to hold the
items
For Each oEnt In objSS
If TypeOf oEnt Is AcadBlockReference Then
Set blkRef = oEnt
If blkRef.HasAttributes = True Then
vAttribs = blkRef.GetAttributes
For Each vAttrib In vAttribs
If vAttrib.TagString = "tagname" And _
vAttrib.TextString = "specifictagvalue" Then
Set oRemItems(I) = blkRef
I = 1 + I
Exit For
End If
Next
End If
End If
Next
ReDim Preserve oRemItems(0 To I - 1)
objSS.RemoveItems oRemItems

Set RemoveItemsFromSS = objSS

End Function
[/code]

wrote in message news:[email protected]...
Thanks for the reply,

I thought that would probably be the case...struggling a bit with
RemoveItem...

So I have a Selection set of all blocks named "myblock". To filter out those
with a particular tag value............

a bit of code so far........
0 Likes
Message 7 of 7

Anonymous
Not applicable
Never mind. Got it.

"adtuser" wrote in message
news:[email protected]...
Hi Jeff,
Why create a separate array? Doesn't the selection set
have a removeitems method?
0 Likes