Need help with sorting/accessing block attribute information

Need help with sorting/accessing block attribute information

Anonymous
Not applicable
275 Views
5 Replies
Message 1 of 6

Need help with sorting/accessing block attribute information

Anonymous
Not applicable
In the attached ZIP is a DWG and a DVB file. The DVB has 2 forms in it.

My goal is to have the program sort blocks based on a particular attribute tag string - This part I can do. However, when I select
the block tag string from a drop down list to display the block's other attributes, it shows a totatlly different block's attributes
instead. It seems as though, even though it's sorted, it's accessing the block information in the order in which the blocks were
created.

My goal is to get UserForm2 to 1) sort the blocks by tag string (which I've already got) and 2) have it show the CORRECT attribute
information that corresponds to the selected block from the drop down list.

Thanks in advance!

--
Matt W
"What the flip was Grandma doing at the sand dunes?"
0 Likes
276 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
No one's willing to take on the challenge??!?
C'mon... Help a brother out.

--
Matt W
"What the flip was Grandma doing at the sand dunes?"
0 Likes
Message 3 of 6

Anonymous
Not applicable
sorry I don't have time to look at your files right now, but if you're
keeping track of your block references via their handles you should get the
correct set of attributes for each block

however you're displaying the tags in your combo box you need to trak the
ref via it's handle
have you tried scripting.dictionaries?

hth
Mark

"Matt W" wrote in message
news:5196331@discussion.autodesk.com...
In the attached ZIP is a DWG and a DVB file. The DVB has 2 forms in it.

My goal is to have the program sort blocks based on a particular attribute
tag string - This part I can do. However, when I select
the block tag string from a drop down list to display the block's other
attributes, it shows a totatlly different block's attributes
instead. It seems as though, even though it's sorted, it's accessing the
block information in the order in which the blocks were
created.

My goa
l is to get UserForm2 to 1) sort the blocks by tag string (which I've
already got) and 2) have it show the CORRECT attribute
information that corresponds to the selected block from the drop down list.

Thanks in advance!

--
Matt W
"What the flip was Grandma doing at the sand dunes?"
0 Likes
Message 4 of 6

Anonymous
Not applicable
As Mark said, you need to use something, such as the handle, to keep track
of what goes with what.....

While not pretty, and could probably be reworked for efficiensy, this
revised FilterBlock Sub does what you need, with a minor change to the
Change event of the lstAtts box.....

Public Sub FilterBlock(strBlockName As String, strAttributeID As String)
Dim varAtts() As AcadAttributeReference
Dim objBlock As AcadBlockReference
Dim FilterType(1) As Integer
Dim FilterData(1) As Variant
Dim obj As AcadEntity
Dim objBlk As AcadBlockReference
Dim I As Integer

Set objBlkSet = GetSelectionSet("BlockFilter")

FilterType(0) = 0
FilterData(0) = "Insert"
FilterType(1) = 2
FilterData(1) = strBlockName

Set colStructureIDs = New Collection
objBlkSet.Select acSelectionSetAll, FilterType:=FilterType,
FilterData:=FilterData
cboStructureIDs.Clear
Dim strAttList() As String
Dim strAttsSorted() As String
If objBlkSet.Count <> 0 Then
ReDim strAttList(0 To objBlkSet.Count - 1, 0 To 1)
ReDim strAttsSorted(0 To objBlkSet.Count - 1, 0 To 1)
Dim J As Integer
For J = 0 To objBlkSet.Count - 1
Set objBlk = objBlkSet(J)
varAtts = objBlk.GetAttributes
For I = LBound(varAtts) To UBound(varAtts)
If UCase$(varAtts(I).TagString) = strAttributeID Then
colStructureIDs.Add varAtts(I).TextString
strAttList(J, 0) = varAtts(I).TextString
strAttList(J, 1) = objBlk.Handle
Exit For
End If
Next I
Next J
BubbleSortCollection colStructureIDs
Dim varAttStr As Variant
J = 0
For Each varAttStr In colStructureIDs
For I = 0 To UBound(strAttList)
If varAttStr = strAttList(I, 0) Then
strAttsSorted(J, 0) = strAttList(I, 0)
strAttsSorted(J, 1) = strAttList(I, 1)
J = J + 1
Exit For
End If
Next I
Next varAttStr
cboStructureIDs.list = strAttsSorted
Else
lstAtts.Clear
End If

End Sub

The minor revison is:
' For intCnt = 0 To cboStructureIDs.ListCount - 1
' Set objBlkRef = objBlkSet.Item(cboStructureIDs.ListIndex)
' Next intCnt
Set objBlkRef =
ThisDrawing.HandleToObject(cboStructureIDs.list(cboStructureIDs.ListIndex,
1))

HTH,
Jeff

"Matt W" wrote in message
news:5197544@discussion.autodesk.com...
No one's willing to take on the challenge??!?
C'mon... Help a brother out.

--
Matt W
"What the flip was Grandma doing at the sand dunes?"
0 Likes
Message 5 of 6

Anonymous
Not applicable
Hmmm... hadn't thought about the handle of the object.
Thanks Jeff.

And Mark, I'll look into modifying the code to use scripting dicitonaries.

Thanks guys!

--
Matt W
"What the flip was Grandma doing at the sand dunes?"
0 Likes
Message 6 of 6

Anonymous
Not applicable
Matt,

I placed a attribute update from excel routine in the customers files that
might help with the handles.

John Coon
"Matt W" wrote in message
news:5198310@discussion.autodesk.com...
Hmmm... hadn't thought about the handle of the object.
Thanks Jeff.

And Mark, I'll look into modifying the code to use scripting dicitonaries.

Thanks guys!

--
Matt W
"What the flip was Grandma doing at the sand dunes?"
0 Likes