<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Edit Nested Block Attributes in VBA in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/edit-nested-block-attributes-in-vba/m-p/9879311#M3922</link>
    <description>&lt;P&gt;Firstly, I'd say having a block reference with attributes added in a block definition (thus, the nested block) isn't a very good practice in most cases. But this is the fact you have not control and have to deal with it using your code...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, let's assume you have a block definition named "MyNestBlock", which has a block reference with attributes (AcadAttributeReference) in it. Following code demonstrates how to edit the attributes of nested block (AcadBlockreference) in a block definition (of course you know all the block reference to this block definition would show the same changes of nested block's attributes):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dim blkDef As AcadBlock&lt;/P&gt;
&lt;P&gt;Set blkDef=ThisDrawing.Blocks("MyNestBlock") '' Assume the block definition does exist in ThisDrawing&lt;/P&gt;
&lt;P&gt;Dim ent As AcadEntity&lt;/P&gt;
&lt;P&gt;Dim blkRef As AcadBlockReference&lt;/P&gt;
&lt;P&gt;Dim att As AcadAttributeReference&lt;/P&gt;
&lt;P&gt;Dim atts As Variant&lt;/P&gt;
&lt;P&gt;Dim i As Integer&lt;/P&gt;
&lt;P&gt;For Each ent in blkDef&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If TypeOf ent Is AcadBlockReference Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set blkRef = ent&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If blkRef.HasAttributes Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; atts=blkRef.GetAttributes()&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; For i=0 To UBound(atts)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set att = atts(i)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Select UCase(att.TagString)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Case "AAAA"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;att.TextString="xxxxxxxxxx"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case "BBBBB"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; att.TextString="yyyyyyyyyy"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ... ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Select&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Next&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Exit For '' Assume you know there is only one nested block reference in the definition&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;Next&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'' After updating the block definition, you may want to Regen the drawing&lt;/P&gt;
&lt;P&gt;ThisDrawing.Regen acAllViewports&lt;/P&gt;
&lt;P&gt;... ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Nov 2020 20:56:34 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2020-11-18T20:56:34Z</dc:date>
    <item>
      <title>Edit Nested Block Attributes in VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/edit-nested-block-attributes-in-vba/m-p/9879138#M3921</link>
      <description>&lt;P&gt;Good Day to everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm running into a bit of an issue here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Sub TestGetAttributes()&lt;/P&gt;&lt;P&gt;Dim varPick As Variant&lt;/P&gt;&lt;P&gt;Dim objEnt As AcadEntity&lt;/P&gt;&lt;P&gt;Dim objBRef As AcadBlockReference&lt;/P&gt;&lt;P&gt;Dim varAttribs As Variant&lt;BR /&gt;Dim strAttribs As String&lt;BR /&gt;Dim intI As Integer&lt;BR /&gt;On Error Resume Next&lt;/P&gt;&lt;P&gt;With ThisDrawing.Utility&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'' get an entity from user&lt;BR /&gt;GetEntity objEnt, varPick, vbCr &amp;amp; "Pick a block with attributes: If Err Then Exit Sub"&lt;/P&gt;&lt;P&gt;'Set Ref&lt;BR /&gt;Set objBRef = objEnt&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;'' exit if not a block&lt;BR /&gt;If objBRef Is Nothing Then&lt;BR /&gt;MsgBox ("That wasn't a block.")&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;'' exit if it has no attributes&lt;BR /&gt;If Not objBRef.HasAttributes Then&lt;BR /&gt;MsgBox ("That block doesn't have attributes.")&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;'' get the attributerefs&lt;BR /&gt;varAttribs = objBRef.GetAttributes&lt;/P&gt;&lt;P&gt;'' Change ASSYNO to the blocks name&lt;BR /&gt;strAttribs = objBRef.Name&lt;BR /&gt;For intI = LBound(varAttribs) To UBound(varAttribs)&lt;BR /&gt;If varAttribs(intI).TagString = "ASSYNO" Then&lt;BR /&gt;varAttribs(intI).TextString = strAttribs&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Next&lt;/P&gt;&lt;P&gt;MsgBox strAttribs&lt;/P&gt;&lt;P&gt;End With&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 19:34:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/edit-nested-block-attributes-in-vba/m-p/9879138#M3921</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-18T19:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Edit Nested Block Attributes in VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/edit-nested-block-attributes-in-vba/m-p/9879311#M3922</link>
      <description>&lt;P&gt;Firstly, I'd say having a block reference with attributes added in a block definition (thus, the nested block) isn't a very good practice in most cases. But this is the fact you have not control and have to deal with it using your code...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, let's assume you have a block definition named "MyNestBlock", which has a block reference with attributes (AcadAttributeReference) in it. Following code demonstrates how to edit the attributes of nested block (AcadBlockreference) in a block definition (of course you know all the block reference to this block definition would show the same changes of nested block's attributes):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dim blkDef As AcadBlock&lt;/P&gt;
&lt;P&gt;Set blkDef=ThisDrawing.Blocks("MyNestBlock") '' Assume the block definition does exist in ThisDrawing&lt;/P&gt;
&lt;P&gt;Dim ent As AcadEntity&lt;/P&gt;
&lt;P&gt;Dim blkRef As AcadBlockReference&lt;/P&gt;
&lt;P&gt;Dim att As AcadAttributeReference&lt;/P&gt;
&lt;P&gt;Dim atts As Variant&lt;/P&gt;
&lt;P&gt;Dim i As Integer&lt;/P&gt;
&lt;P&gt;For Each ent in blkDef&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If TypeOf ent Is AcadBlockReference Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set blkRef = ent&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If blkRef.HasAttributes Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; atts=blkRef.GetAttributes()&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; For i=0 To UBound(atts)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set att = atts(i)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Select UCase(att.TagString)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Case "AAAA"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;att.TextString="xxxxxxxxxx"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case "BBBBB"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; att.TextString="yyyyyyyyyy"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ... ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Select&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Next&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Exit For '' Assume you know there is only one nested block reference in the definition&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;Next&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'' After updating the block definition, you may want to Regen the drawing&lt;/P&gt;
&lt;P&gt;ThisDrawing.Regen acAllViewports&lt;/P&gt;
&lt;P&gt;... ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 20:56:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/edit-nested-block-attributes-in-vba/m-p/9879311#M3922</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-11-18T20:56:34Z</dc:date>
    </item>
  </channel>
</rss>

