Here is my very basic example,
just change a block name within the code
Code:
<CommandMethod("DisplayAttributes", "diat", CommandFlags.Modal + CommandFlags.UsePickSet)> _
Public Sub GetAttributesTest()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim attref As AttributeReference = Nothing
Dim bref As BlockReference = Nothing
Dim blkname As String = "MYBLOCK" '' <--- change block name
Dim attTag As String = String.Empty
Try
Dim tr As Transaction = db.TransactionManager.StartTransaction()
Using tr
Dim selres As PromptSelectionResult = Nothing
Dim tvs() As TypedValue = New TypedValue() {New TypedValue(0, "insert"), _
New TypedValue(66, 1), _
New TypedValue(2, "`U*," + blkname)}
Dim filt As SelectionFilter = New SelectionFilter(tvs)
selres = ed.GetSelection(filt)
If selres.Status <> PromptStatus.OK Then
Return
End If
Dim selset As SelectionSet = selres.Value
Dim bname As String = String.Empty
For Each selobj As SelectedObject In selset
Dim sent As Entity = DirectCast(tr.GetObject(selobj.ObjectId, OpenMode.ForRead), Entity)
If TypeOf sent Is BlockReference Then
Dim obr As BlockReference = DirectCast(sent, BlockReference)
If obr.IsDynamicBlock Then
Dim dynId As ObjectId = obr.DynamicBlockTableRecord
If dynId.IsNull Or dynId.IsErased Then
Continue For
End If
Dim dynbtr As BlockTableRecord = TryCast(tr.GetObject(dynId, OpenMode.ForRead), BlockTableRecord)
If dynbtr IsNot Nothing Then
bname = dynbtr.Name
End If
Else
bname = obr.Name
End If
If bname = blkname Then
For Each attId As ObjectId In obr.AttributeCollection
attref = DirectCast(tr.GetObject(attId, OpenMode.ForRead, False), AttributeReference)
ed.WriteMessage(vbLf + "Block Name: {0}" + vbLf + "Tag: {1}" + vbLf + "Value: {2}", bname, attref.Tag, attref.TextString)
Next
End If
End If
Next
tr.Commit()
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.ToString)
End Try
End Sub
~'J'~