Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi:
I want to change the attributes of a block contained in a dynamic block.
I have managed to change the attributes when the block is static.
I leave the code I am using.
Sub UpdateAtts1(BlockID As Object, NombreBloqueHijo As String, prefijo As String, tagstring As String, contador As Integer)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim i As Integer = contador
Using docloc As DocumentLock = doc.LockDocument
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim br As BlockReference = CType(tr.GetObject(BlockID, OpenMode.ForRead), BlockReference)
Dim btr As BlockTableRecord = Nothing
If br.IsDynamicBlock Then
Dim btrHijo As BlockTableRecord = CType(tr.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead), BlockTableRecord)
For Each id As ObjectId In btrHijo
If id.ObjectClass.Name = "AcDbBlockReference" Then
Dim brHijo As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForRead), BlockReference)
If brHijo.Name = NombreBloqueHijo Then
For Each attId As ObjectId In brHijo.AttributeCollection
Dim attRef As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)
If attRef.Tag = tagstring Then
attRef.UpgradeOpen()
attRef.TextString = prefijo & i
i += 1
Exit For
End If
Next
End If
End If
Next
Else
btr = CType(tr.GetObject(br.BlockTableRecord, OpenMode.ForWrite), BlockTableRecord)
For Each id As ObjectId In btr
If id.ObjectClass.Name = "AcDbBlockReference" Then
Dim brHijo As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForRead), BlockReference)
If brHijo.Name = NombreBloqueHijo Then
For Each attId As ObjectId In brHijo.AttributeCollection
Dim attRef As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)
If attRef.Tag = tagstring Then
attRef.UpgradeOpen()
attRef.TextString = prefijo & i
i += 1
Exit For
End If
Next
End If
End If
Next
End If
tr.Commit()
End Using
End Using
ed.Regen()
End Sub
Thank you
Greetings
Solved! Go to Solution.