- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I’m new to this and I do need to understand better how to access the BTR, read and write BRef, attDef, AttRef etc. But this has me stumped. There are a few different examples but can’t find anything that works and don't know why.
I have inserted a block in modelspace, I have the BlockRefID and now want to change its attribute values.
This finds the attributes tags but doesn’t write the sValue. Can anyone spot why it isn’t writing the value to the block or suggest something better
Public Sub ChangeAttributeValue(ByVal BlockRefID As ObjectId, ByVal sTagName As String, ByVal sValue As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim tr As Transaction = db.TransactionManager.StartTransaction()
Dim br As BlockReference = DirectCast(tr.GetObject(BlockRefID, OpenMode.ForWrite), BlockReference)
Dim RefBTR As BlockTableRecord = tr.GetObject(br.BlockTableRecord, OpenMode.ForRead)
Dim attEnt As Entity
Try
For Each attID As ObjectId In RefBTR
attEnt = tr.GetObject(attID, OpenMode.ForRead)
If TypeOf attEnt Is AttributeDefinition Then
Dim attDef As AttributeDefinition = attEnt
Dim attRef As AttributeReference = New AttributeReference()
attRef.SetAttributeFromBlock(attDef, br.BlockTransform)
If attRef.Tag = sTagName Then
attRef.TextString = sValue
Exit Sub
End If
End If
Next
Catch ex As Autodesk.AutoCAD.Runtime.Exception
tr.Abort()
Finally
tr.Commit()
End Try
End Sub
Hope someone can help.
Solved! Go to Solution.