You can retrieve the constant attributes from BlockTableRecord, eg.:
Code:
<CommandMethod("gatt", CommandFlags.Modal Or CommandFlags.Session)> _
Public Shared Sub GetAttributesTest()
Dim doc As Document = acApp.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using docloc As DocumentLock = doc.LockDocument
Using tr As Transaction = db.TransactionManager.StartTransaction
Try
Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
'Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
Dim pso As PromptSelectionOptions = New PromptSelectionOptions
pso.MessageForRemoval = vbCr & "Wrong objects selected or Nothing selected"
pso.MessageForAdding = vbCr & "Select Blocks"
Dim tvs() As TypedValue = New TypedValue() {New TypedValue(0, "INSERT")}
Dim filt As SelectionFilter = New SelectionFilter(tvs)
Dim psr As PromptSelectionResult = ed.GetSelection(pso, filt)
If Not psr.Status = PromptStatus.OK Then Exit Sub
If psr.Value.Count = 0 Then
ed.WriteMessage("{0}Count: {1}blocks", vbNewLine, psr.Value.Count)
Exit Sub
End If
For Each sobj As SelectedObject In psr.Value
Dim bref As BlockReference = CType(tr.GetObject(sobj.ObjectId, OpenMode.ForRead), BlockReference)
Dim btrec As BlockTableRecord = CType(tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
Dim sb As New StringBuilder
'Get constant attributes from BlockDefinition object
For Each eid As ObjectId In btrec
Dim obj As DBObject = CType(tr.GetObject(eid, OpenMode.ForRead), Entity)
If (TypeOf (obj) Is AttributeDefinition) Then
Dim atdef As AttributeDefinition = obj
If atdef.Constant Then
sb.AppendLine(atdef.TextString)
End If
End If
Next
'Get visible attributes from BlockReference object
Dim attcoll As AttributeCollection = bref.AttributeCollection
For Each id As ObjectId In attcoll
Dim atref As AttributeReference = CType(tr.GetObject(id, OpenMode.ForRead), AttributeReference)
sb.AppendLine(atref.TextString)
Next
ed.WriteMessage(sb.ToString + vbLf)
Next
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(vbCr & ex.Message & vbCr & ex.StackTrace)
End Try
End Using
End Using
End Sub
~'J'~