Hi,
you can read blockreference attributes easily with transaction. The WorldDraw function Overrides all BlockRefereces only. Example reads blocks attribute value and display that with wd.Geometry.Text function. You have to create Autodesk.AutoCAD.GraphicsInterface.TextStyle for that.
Cheers
Veli V.
Public Overrides Function WorldDraw(drawable As Autodesk.AutoCAD.GraphicsInterface.Drawable, wd As Autodesk.AutoCAD.GraphicsInterface.WorldDraw) As Boolean
Dim oAttrib As AttributeReference = Nothing
Dim blk As BlockReference = DirectCast(drawable, BlockReference)
If Not blk Is Nothing Then
Dim attCol As AttributeCollection = blk.AttributeCollection
Dim attTextPosYDiff As Double = 0.0
Dim sAttribTexts As New List(Of String)
ed.WriteMessage("BlockReference: " + blk.Name + vbCrLf)
If blk.Name.Trim.ToLower = "kltaite" Then
Try
Using tr As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartOpenCloseTransaction
For Each attObjId As ObjectId In attCol
oAttrib = DirectCast(tr.GetObject(attObjId, OpenMode.ForRead), AttributeReference)
'ed.WriteMessage("BlockAttribute: " + oAttrib.Tag + vbCrLf)
sAttribTexts.Add(oAttrib.Tag + " = " + oAttrib.TextString)
Next attObjId
tr.Commit()
End Using
Catch ex As Exception
Debug.WriteLine("Error while reading block " + blk.Name + " attribute. " + ex.Message)
ed.WriteMessage("Error while reading block " + blk.Name + " attribute. " + ex.Message + vbCrLf)
End Try
If Not sAttribTexts Is Nothing Then
For Each sVal As String In sAttribTexts
wd.Geometry.Text(New Autodesk.AutoCAD.Geometry.Point3d(blk.Position.X, blk.Position.Y - attTextPosYDiff, blk.Position.Z), _TextNormal, _TextDirect, sVal, True, _style)
attTextPosYDiff += 0.5
Next sVal
End If
wd.Geometry.Circle(blk.Position, 1, New Autodesk.AutoCAD.Geometry.Vector3d(0, 0, 1))
Using sol3d As New Solid3d()
sol3d.CreateSphere(0.2)
sol3d.TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(blk.Position - Autodesk.AutoCAD.Geometry.Point3d.Origin))
sol3d.WorldDraw(wd)
End Using
End If
sAttribTexts.Clear() : sAttribTexts = Nothing
End If
Return MyBase.WorldDraw(drawable, wd)
End Function