<?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: Accessing Blocks Inside Blocks in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11082361#M13295</link>
    <description>&lt;P&gt;Is this method using different dll's ? I have to keep the program under the Autodesk.AutoCAD.Interop and Interop.Common dll's&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2022 19:36:37 GMT</pubDate>
    <dc:creator>felix.cortes5K3Y2</dc:creator>
    <dc:date>2022-04-04T19:36:37Z</dc:date>
    <item>
      <title>Accessing Blocks Inside Blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11081359#M13293</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am writing a program that analyzes the attributes of blocks in an layout. However, I cannot find the way to access AcadBlockReference's of blocks inside a block. Anyone have an idea how to approach this? Here's my lines of code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imports Autodesk.AutoCAD.Interop&lt;BR /&gt;Imports Autodesk.AutoCAD.Interop.Common&lt;BR /&gt;Imports System.Runtime.InteropServices&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sub Main()&lt;BR /&gt;Dim acad As AcadApplication = Marshal.GetActiveObject("Autocad.Application")&lt;BR /&gt;Dim acadDoc As AcadDocument = acad.ActiveDocument&lt;BR /&gt;Dim layout As AcadLayout = acadDoc.Layouts.Item("Model")&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;Sub RunProgram(Lay As AcadLayout)&lt;BR /&gt;Dim Ent As AcadEntity&lt;BR /&gt;Dim Blk As AcadBlockReference&lt;BR /&gt;For i As Integer = 0 To Lay.Block.Count&lt;BR /&gt;Ent = Lay.Block.Item(i)&lt;BR /&gt;If TypeOf Ent Is AcadBlockReference Then&lt;BR /&gt;Call ProcessBlock(Ent)&lt;BR /&gt;End If&lt;BR /&gt;Next&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;Sub ProcessBlock(Blk As AcadBlockReference)&lt;BR /&gt;Debug.Print("Name: {0}", Blk.EffectiveName)&lt;BR /&gt;'if block has blocks inside, ProcessBlock(New block)&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 12:51:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11081359#M13293</guid>
      <dc:creator>felix.cortes5K3Y2</dc:creator>
      <dc:date>2022-04-04T12:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Blocks Inside Blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11081756#M13294</link>
      <description>&lt;P&gt;Here is a quick example of navigating through nested blocks.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt; Dim block As BlockTableRecord
            Using tr As Transaction = db.TransactionManager.StartTransaction
                Dim blk As BlockReference = tr.GetObject(res.ObjectId, OpenMode.ForRead)

                If blk.IsDynamicBlock Then
                    block = tr.GetObject(blk.DynamicBlockTableRecord, OpenMode.ForRead)
                Else
                    block = tr.GetObject(blk.BlockTableRecord, OpenMode.ForRead)
                End If

                ed.WriteMessage(vbCrLf &amp;amp; "Block Name: " &amp;amp; block.Name)

                PrintNestedBlocks(block, tr, 0)

                tr.Commit()
            End Using&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Public Sub PrintNestedBlocks(block As BlockTableRecord, tr As Transaction, nestLevel As Integer)
            For Each id As ObjectId In block
                Dim ent As Entity = tr.GetObject(id, OpenMode.ForRead)
                If TypeOf ent Is BlockReference Then
                    Dim blkRef As BlockReference = TryCast(ent, BlockReference)
                    If blkRef.IsDynamicBlock Then
                        block = tr.GetObject(blkRef.DynamicBlockTableRecord, OpenMode.ForRead)
                    Else
                        block = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead)
                    End If

                    Dim pad As String = ""
                    For i As Integer = 0 To nestLevel
                        pad += vbTab
                    Next

                    ed.WriteMessage(vbCrLf &amp;amp; pad &amp;amp; "Block Name: " &amp;amp; block.Name)

                    PrintNestedBlocks(block, tr, nestLevel + 1)

                End If
            Next
        End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 15:22:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11081756#M13294</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2022-04-04T15:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Blocks Inside Blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11082361#M13295</link>
      <description>&lt;P&gt;Is this method using different dll's ? I have to keep the program under the Autodesk.AutoCAD.Interop and Interop.Common dll's&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 19:36:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11082361#M13295</guid>
      <dc:creator>felix.cortes5K3Y2</dc:creator>
      <dc:date>2022-04-04T19:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Blocks Inside Blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11101858#M13296</link>
      <description>&lt;P&gt;Are you looking for something like this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Private Sub PrintNestedNames(blk As AcadBlock, acdb As AcadDatabase, ed As Editor)
            ed.WriteMessage(vbCrLf &amp;amp; "Block Name: " &amp;amp; blk.Name)
            For Each ent As AcadEntity In blk
                If TypeOf ent Is AcadBlockReference Then
                    Dim bRef As AcadBlockReference = ent
                    Dim b As AcadBlock = GetAcadBlock(bRef.EffectiveName, acdb)
                    If b IsNot Nothing Then
                        PrintNestedNames(b, acdb, ed)
                    End If
                End If
            Next
        End Sub

        Private Function GetAcadBlock(name As String, acdb As AcadDatabase) As AcadBlock
            For Each blk As AcadBlock In acdb.Blocks
                If blk.Name = name Then
                    Return blk
                End If
            Next
            Return Nothing
        End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 19:51:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11101858#M13296</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2022-04-12T19:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Blocks Inside Blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11125374#M13297</link>
      <description>&lt;P&gt;Doesn't seem to work, I need to filter through each AcadBlockReference inside a layout to search for specific blocks and inside nested blocks as well&lt;/P&gt;</description>
      <pubDate>Sun, 24 Apr 2022 18:27:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-blocks-inside-blocks/m-p/11125374#M13297</guid>
      <dc:creator>felix.cortes5K3Y2</dc:creator>
      <dc:date>2022-04-24T18:27:02Z</dc:date>
    </item>
  </channel>
</rss>

