Edit Nested Block Attributes in VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good Day to everyone,
I'm running into a bit of an issue here.
My purpose is to write a VBA code that will edit a particular attribute of all the nested blocks within the selected parent block. I have so far achieved a code that can change the particular attribute of a non nested block my desired value.
I figure with this code, all I would need to do is add "For each Entity (child blocks) within the Entity ( parent that i have chosen)". But this is seemingly wrong, maybe because i need to look for entities within the Block Reference and not the block itself,I'm really not too sure.
I've attached below the code that works for a single non nested block, would anyone point me in the right direction to make this work by selecting a parent block, and having all ASSYNO attributes changed to the parent blocks name?
Public Sub TestGetAttributes()
Dim varPick As Variant
Dim objEnt As AcadEntity
Dim objBRef As AcadBlockReference
Dim varAttribs As Variant
Dim strAttribs As String
Dim intI As Integer
On Error Resume Next
With ThisDrawing.Utility
'' get an entity from user
GetEntity objEnt, varPick, vbCr & "Pick a block with attributes: If Err Then Exit Sub"
'Set Ref
Set objBRef = objEnt
'' exit if not a block
If objBRef Is Nothing Then
MsgBox ("That wasn't a block.")
End If
'' exit if it has no attributes
If Not objBRef.HasAttributes Then
MsgBox ("That block doesn't have attributes.")
End If
'' get the attributerefs
varAttribs = objBRef.GetAttributes
'' Change ASSYNO to the blocks name
strAttribs = objBRef.Name
For intI = LBound(varAttribs) To UBound(varAttribs)
If varAttribs(intI).TagString = "ASSYNO" Then
varAttribs(intI).TextString = strAttribs
End If
Next
MsgBox strAttribs
End With
End Sub