TheSwamp
Code Red => VB(A) => Topic started by: Guest on September 07, 2007, 09:46:09 AM
-
I've got a program that counts various blocks using different selection types. Right now, I've got it so that it will count the blocks based on the value of an attribute tag. And now I want to add the block name to the mix because some blocks may have the same attribute value as others.
So right now the code spits out something like this...
A 3
B 6
C 12
I want to add the block name so that the count looks more like this to show which block is associated with the attribute value.
Block 1
A 3
Block 2
B 3
Block C
B 3
Block D
C 9
Block E
C 3
Here's my code thus far. I've got a reference to the MS Scripting Runtime for creating the dictionaries.
Private Sub GetAttributeCount()
Dim objAttKeys As Variant
Dim objAttItems As Variant
Dim objAttDict As Dictionary
Dim varAtts() As AcadAttributeReference
Dim objBlock As AcadBlockReference
Dim obj As AcadEntity
Dim i, x As Integer
Set objAttDict = New Dictionary
x = 1
For Each obj In SSet
Set objBlock = obj
If obj.HasAttributes Then
varAtts = obj.GetAttributes
For i = LBound(varAtts) To UBound(varAtts)
If UCase$(varAtts(i).TagString) = "DATATYPE" Then
If objAttDict.Exists(varAtts(i).TextString) = False Then
objAttDict.Add varAtts(i).TextString, 1
Else
objAttDict.item(varAtts(i).TextString) = objAttDict.item(varAtts(i).TextString) + 1
End If
End If
On Error GoTo 0
Next i
End If
Next obj
i = 0
objAttKeys = objAttDict.Keys
objAttItems = objAttDict.Items
For x = 0 To UBound(objAttKeys)
Debug.Print objAttKeys(x) & vbTab & objAttItems(x)
i = i + objAttItems(x)
Next
End Sub
-
Hi Matt
Look at this thread
http://discussion.autodesk.com/thread.jspa?threadID=606029
Hope it may helps
~'J'~
-
The dictionary may not be the best container for this.
It seems to me that you can have
Block1 A 3 and Block1 B 2.
By parsing the comma you could achieve this with
"Block1,A" 3 and "Block1,B" 2
but it's usually easier to use a variant array in a collection.
Dim Bc(2)
BC(0)=block.name:Bc(1)=Att.textstring:Bc(2)=count
Now you make a selset for each blockref by name,
Sort the Bcs for that block
add to the collection
-
Thanks guys!
This will give me something to think about.