<?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: Getting nested block? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418840#M83993</link>
    <description>Not sure exactly what that code is supposed to do, but why are you getting &lt;BR /&gt;
the BlockTableRecord's ObjectId by looking it up in the block table using &lt;BR /&gt;
the block's name, when the BlockReference already gives you the id (the &lt;BR /&gt;
BlockTableRecord and DynamicBlockTableRecord property) ??&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;ARCTICAD&gt; wrote in message news:6293088@discussion.autodesk.com...&lt;BR /&gt;
Here is an Example to let you modify the blocks recursively.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Colors&lt;BR /&gt;
&lt;BR /&gt;
' This is an example of selecting a block on the screen and recursively &lt;BR /&gt;
accessing each block&lt;BR /&gt;
&lt;BR /&gt;
Public Class Sample&lt;BR /&gt;
&lt;BR /&gt;
  Sub Recursive()&lt;BR /&gt;
        Dim Col As New Collection&lt;BR /&gt;
        GetBlockSelection(Col)&lt;BR /&gt;
        Dim blockschecked As New Collection&lt;BR /&gt;
        RecursiveBlockDefinition(Col, blockschecked)&lt;BR /&gt;
        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.Regen()&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub RecursiveBlockDefinition(ByVal Col As Collection, ByRef &lt;BR /&gt;
BlocksChecked As Collection)&lt;BR /&gt;
        ' Use BlocksChecked to check if you already modified the block&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
            Using tr As Transaction = &lt;BR /&gt;
db.TransactionManager.StartTransaction()&lt;BR /&gt;
                Dim dwg As Document = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
                Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;
                    Dim BT As BlockTable = &lt;BR /&gt;
dwg.Database.BlockTableId.GetObject(OpenMode.ForWrite)&lt;BR /&gt;
&lt;BR /&gt;
                    If Col.Count &amp;gt; 0 Then&lt;BR /&gt;
                        For i = 1 To Col.Count&lt;BR /&gt;
                            If Not BlocksChecked.Contains(Col(i).ToString) &lt;BR /&gt;
Then&lt;BR /&gt;
                                Dim e As Entity = tr.GetObject(Col(i), &lt;BR /&gt;
OpenMode.ForWrite)&lt;BR /&gt;
                                If TypeOf e Is BlockReference Then&lt;BR /&gt;
                                    ' Add to Checked List&lt;BR /&gt;
                                    If Not &lt;BR /&gt;
BlocksChecked.Contains(e.ObjectId.ToString) Then&lt;BR /&gt;
                                        BlocksChecked.Add(e.ObjectId, &lt;BR /&gt;
e.ObjectId.ToString)&lt;BR /&gt;
                                    End If&lt;BR /&gt;
                                    Dim b As BlockReference = &lt;BR /&gt;
tr.GetObject(Col(i), OpenMode.ForWrite)&lt;BR /&gt;
                                    Dim BTR As BlockTableRecord = &lt;BR /&gt;
tr.GetObject(BT(b.Name), OpenMode.ForWrite)&lt;BR /&gt;
                                    If Not (BTR.IsFromExternalReference Or &lt;BR /&gt;
BTR.IsFromOverlayReference) Then&lt;BR /&gt;
                                        For Each item As ObjectId In BTR&lt;BR /&gt;
                                            ' Change Object's Color to red&lt;BR /&gt;
                                            Dim e2 As Entity = &lt;BR /&gt;
tr.GetObject(item, OpenMode.ForWrite)&lt;BR /&gt;
                                            e2.Color = &lt;BR /&gt;
Color.FromColorIndex(ColorMethod.ByAci, 1)&lt;BR /&gt;
                                            If TypeOf e2 Is BlockReference &lt;BR /&gt;
Then&lt;BR /&gt;
                                                Dim Lcol As New Collection&lt;BR /&gt;
                                                Lcol.Add(e2.ObjectId)&lt;BR /&gt;
                                                RecursiveBlockDefinition(Lcol, &lt;BR /&gt;
BlocksChecked)&lt;BR /&gt;
                                            End If&lt;BR /&gt;
                                        Next&lt;BR /&gt;
                                    End If&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Next&lt;BR /&gt;
                        tr.Commit()&lt;BR /&gt;
                        BT.Dispose()&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub GetBlockSelection(ByRef ColObjID As Collection)&lt;BR /&gt;
        Dim activeDocument As Document = &lt;BR /&gt;
Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim activeDB As Database = activeDocument.Database&lt;BR /&gt;
&lt;BR /&gt;
        Dim ed As Editor = activeDocument.Editor&lt;BR /&gt;
&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
            Using trans As Transaction = &lt;BR /&gt;
db.TransactionManager.StartTransaction()&lt;BR /&gt;
                Dim dwg As Document = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
                Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;
&lt;BR /&gt;
                    Dim selectionTypeValue As TypedValue() = New &lt;BR /&gt;
TypedValue(0) {}&lt;BR /&gt;
                    selectionTypeValue.SetValue(New &lt;BR /&gt;
TypedValue(CInt(DxfCode.Start), "INSERT"), 0)&lt;BR /&gt;
&lt;BR /&gt;
                    Dim selectionFilter As New &lt;BR /&gt;
SelectionFilter(selectionTypeValue)&lt;BR /&gt;
&lt;BR /&gt;
                    Dim getSelectionResult As PromptSelectionResult&lt;BR /&gt;
                    getSelectionResult = ed.GetSelection(selectionFilter)&lt;BR /&gt;
&lt;BR /&gt;
                    ' If selection actually contains something&lt;BR /&gt;
                    If getSelectionResult.Status = PromptStatus.OK Then&lt;BR /&gt;
                        Dim selectionSet As SelectionSet = &lt;BR /&gt;
getSelectionResult.Value&lt;BR /&gt;
&lt;BR /&gt;
                        For Each selectedObject As SelectedObject In &lt;BR /&gt;
selectionSet&lt;BR /&gt;
                            If selectedObject IsNot Nothing Then&lt;BR /&gt;
                                Dim selectedEntity As Entity = &lt;BR /&gt;
TryCast(trans.GetObject(selectedObject.ObjectId, OpenMode.ForWrite), Entity)&lt;BR /&gt;
                                If Not &lt;BR /&gt;
ColObjID.Contains(selectedEntity.ObjectId.ToString) Then&lt;BR /&gt;
                                    ColObjID.Add(selectedEntity.ObjectId, &lt;BR /&gt;
selectedEntity.ObjectId.ToString)&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Next&lt;BR /&gt;
&lt;BR /&gt;
                        trans.Commit()&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
&lt;BR /&gt;
        Dim curDoc As Document = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        ' Clear Command Line&lt;BR /&gt;
        curDoc.SendStringToExecute(Chr(27), False, False, False)&lt;BR /&gt;
    End Sub&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;/ARCTICAD&gt;</description>
    <pubDate>Sat, 21 Nov 2009 21:48:16 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2009-11-21T21:48:16Z</dc:date>
    <item>
      <title>Getting nested block?</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418835#M83988</link>
      <description>I am writing a utility to iterate through all the blocks in model space.  Many of the blocks that I am iterating through may have sub-blocks nested within them, which I also need to iterate through.  Does anyone know how I can get at these sub-blocks from the top-level block?  There's probably a way to do it by exploding the top block, but I'd rather not use that approach if possible.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the help!&lt;BR /&gt;
&lt;BR /&gt;
Brian</description>
      <pubDate>Tue, 30 Aug 2005 05:44:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418835#M83988</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-08-30T05:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nested block?</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418836#M83989</link>
      <description>brianroth,&lt;BR /&gt;
&lt;BR /&gt;
I presume you have worked this out by now, but if not check out "Working With Nested Blocks" thread where some solutions to this are now posted.  &lt;BR /&gt;
&lt;BR /&gt;
I just learned about this post from another forum user...</description>
      <pubDate>Thu, 19 Nov 2009 15:48:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418836#M83989</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T15:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nested block?</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418837#M83990</link>
      <description>u could browse through the entities of the block via .NET. Also, by using recursion, you could keep browsing for entities inside blocks until you get what you want.</description>
      <pubDate>Fri, 20 Nov 2009 08:25:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418837#M83990</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-20T08:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nested block?</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418838#M83991</link>
      <description>I did not find this straight forward as the nested blocks do not exist in model space with the parent block reference, but only in the block definition of parent block.  &lt;BR /&gt;
The idea of recursion is interesting,  Not sure how it could be done however....&lt;BR /&gt;
See the "Working with Nested Blocks" for all the details of what I was trying to do and then let me know if your can spot another approach.</description>
      <pubDate>Fri, 20 Nov 2009 17:30:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418838#M83991</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-20T17:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nested block?</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418839#M83992</link>
      <description>Here is an Example to let you modify the blocks recursively. &lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Colors&lt;BR /&gt;
&lt;BR /&gt;
' This is an example of selecting a block on the screen and recursively accessing each block&lt;BR /&gt;
&lt;BR /&gt;
Public Class Sample&lt;BR /&gt;
 &lt;BR /&gt;
  Sub Recursive()&lt;BR /&gt;
        Dim Col As New Collection&lt;BR /&gt;
        GetBlockSelection(Col)&lt;BR /&gt;
        Dim blockschecked As New Collection&lt;BR /&gt;
        RecursiveBlockDefinition(Col, blockschecked)&lt;BR /&gt;
        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.Regen()&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub RecursiveBlockDefinition(ByVal Col As Collection, ByRef BlocksChecked As Collection)&lt;BR /&gt;
        ' Use BlocksChecked to check if you already modified the block&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
            Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
                Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
                Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;
                    Dim BT As BlockTable = dwg.Database.BlockTableId.GetObject(OpenMode.ForWrite)&lt;BR /&gt;
&lt;BR /&gt;
                    If Col.Count &amp;gt; 0 Then&lt;BR /&gt;
                        For i = 1 To Col.Count&lt;BR /&gt;
                            If Not BlocksChecked.Contains(Col(i).ToString) Then&lt;BR /&gt;
                                Dim e As Entity = tr.GetObject(Col(i), OpenMode.ForWrite)&lt;BR /&gt;
                                If TypeOf e Is BlockReference Then&lt;BR /&gt;
                                    ' Add to Checked List&lt;BR /&gt;
                                    If Not BlocksChecked.Contains(e.ObjectId.ToString) Then&lt;BR /&gt;
                                        BlocksChecked.Add(e.ObjectId, e.ObjectId.ToString)&lt;BR /&gt;
                                    End If      &lt;BR /&gt;
                                    Dim b As BlockReference = tr.GetObject(Col(i), OpenMode.ForWrite)&lt;BR /&gt;
                                    Dim BTR As BlockTableRecord = tr.GetObject(BT(b.Name), OpenMode.ForWrite)&lt;BR /&gt;
                                    If Not (BTR.IsFromExternalReference Or BTR.IsFromOverlayReference) Then&lt;BR /&gt;
                                        For Each item As ObjectId In BTR&lt;BR /&gt;
                                            ' Change Object's Color to red&lt;BR /&gt;
                                            Dim e2 As Entity = tr.GetObject(item, OpenMode.ForWrite)&lt;BR /&gt;
                                            e2.Color = Color.FromColorIndex(ColorMethod.ByAci, 1)&lt;BR /&gt;
                                            If TypeOf e2 Is BlockReference Then&lt;BR /&gt;
                                                Dim Lcol As New Collection&lt;BR /&gt;
                                                Lcol.Add(e2.ObjectId)&lt;BR /&gt;
                                                RecursiveBlockDefinition(Lcol, BlocksChecked)&lt;BR /&gt;
                                            End If&lt;BR /&gt;
                                        Next&lt;BR /&gt;
                                    End If&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Next&lt;BR /&gt;
                        tr.Commit()&lt;BR /&gt;
                        BT.Dispose()&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub GetBlockSelection(ByRef ColObjID As Collection)&lt;BR /&gt;
        Dim activeDocument As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim activeDB As Database = activeDocument.Database&lt;BR /&gt;
&lt;BR /&gt;
        Dim ed As Editor = activeDocument.Editor&lt;BR /&gt;
&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
            Using trans As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
                Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
                Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;
&lt;BR /&gt;
                    Dim selectionTypeValue As TypedValue() = New TypedValue(0) {}&lt;BR /&gt;
                    selectionTypeValue.SetValue(New TypedValue(CInt(DxfCode.Start), "INSERT"), 0)&lt;BR /&gt;
&lt;BR /&gt;
                    Dim selectionFilter As New SelectionFilter(selectionTypeValue)&lt;BR /&gt;
&lt;BR /&gt;
                    Dim getSelectionResult As PromptSelectionResult&lt;BR /&gt;
                    getSelectionResult = ed.GetSelection(selectionFilter)&lt;BR /&gt;
&lt;BR /&gt;
                    ' If selection actually contains something&lt;BR /&gt;
                    If getSelectionResult.Status = PromptStatus.OK Then&lt;BR /&gt;
                        Dim selectionSet As SelectionSet = getSelectionResult.Value&lt;BR /&gt;
&lt;BR /&gt;
                        For Each selectedObject As SelectedObject In selectionSet&lt;BR /&gt;
                            If selectedObject IsNot Nothing Then&lt;BR /&gt;
                                Dim selectedEntity As Entity = TryCast(trans.GetObject(selectedObject.ObjectId, OpenMode.ForWrite), Entity)&lt;BR /&gt;
                                If Not ColObjID.Contains(selectedEntity.ObjectId.ToString) Then&lt;BR /&gt;
                                    ColObjID.Add(selectedEntity.ObjectId, selectedEntity.ObjectId.ToString)&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Next&lt;BR /&gt;
&lt;BR /&gt;
                        trans.Commit()&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
&lt;BR /&gt;
        Dim curDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        ' Clear Command Line&lt;BR /&gt;
        curDoc.SendStringToExecute(Chr(27), False, False, False)&lt;BR /&gt;
    End Sub&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
{code}</description>
      <pubDate>Sat, 21 Nov 2009 01:20:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418839#M83992</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2009-11-21T01:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nested block?</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418840#M83993</link>
      <description>Not sure exactly what that code is supposed to do, but why are you getting &lt;BR /&gt;
the BlockTableRecord's ObjectId by looking it up in the block table using &lt;BR /&gt;
the block's name, when the BlockReference already gives you the id (the &lt;BR /&gt;
BlockTableRecord and DynamicBlockTableRecord property) ??&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;ARCTICAD&gt; wrote in message news:6293088@discussion.autodesk.com...&lt;BR /&gt;
Here is an Example to let you modify the blocks recursively.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Colors&lt;BR /&gt;
&lt;BR /&gt;
' This is an example of selecting a block on the screen and recursively &lt;BR /&gt;
accessing each block&lt;BR /&gt;
&lt;BR /&gt;
Public Class Sample&lt;BR /&gt;
&lt;BR /&gt;
  Sub Recursive()&lt;BR /&gt;
        Dim Col As New Collection&lt;BR /&gt;
        GetBlockSelection(Col)&lt;BR /&gt;
        Dim blockschecked As New Collection&lt;BR /&gt;
        RecursiveBlockDefinition(Col, blockschecked)&lt;BR /&gt;
        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.Regen()&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub RecursiveBlockDefinition(ByVal Col As Collection, ByRef &lt;BR /&gt;
BlocksChecked As Collection)&lt;BR /&gt;
        ' Use BlocksChecked to check if you already modified the block&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
            Using tr As Transaction = &lt;BR /&gt;
db.TransactionManager.StartTransaction()&lt;BR /&gt;
                Dim dwg As Document = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
                Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;
                    Dim BT As BlockTable = &lt;BR /&gt;
dwg.Database.BlockTableId.GetObject(OpenMode.ForWrite)&lt;BR /&gt;
&lt;BR /&gt;
                    If Col.Count &amp;gt; 0 Then&lt;BR /&gt;
                        For i = 1 To Col.Count&lt;BR /&gt;
                            If Not BlocksChecked.Contains(Col(i).ToString) &lt;BR /&gt;
Then&lt;BR /&gt;
                                Dim e As Entity = tr.GetObject(Col(i), &lt;BR /&gt;
OpenMode.ForWrite)&lt;BR /&gt;
                                If TypeOf e Is BlockReference Then&lt;BR /&gt;
                                    ' Add to Checked List&lt;BR /&gt;
                                    If Not &lt;BR /&gt;
BlocksChecked.Contains(e.ObjectId.ToString) Then&lt;BR /&gt;
                                        BlocksChecked.Add(e.ObjectId, &lt;BR /&gt;
e.ObjectId.ToString)&lt;BR /&gt;
                                    End If&lt;BR /&gt;
                                    Dim b As BlockReference = &lt;BR /&gt;
tr.GetObject(Col(i), OpenMode.ForWrite)&lt;BR /&gt;
                                    Dim BTR As BlockTableRecord = &lt;BR /&gt;
tr.GetObject(BT(b.Name), OpenMode.ForWrite)&lt;BR /&gt;
                                    If Not (BTR.IsFromExternalReference Or &lt;BR /&gt;
BTR.IsFromOverlayReference) Then&lt;BR /&gt;
                                        For Each item As ObjectId In BTR&lt;BR /&gt;
                                            ' Change Object's Color to red&lt;BR /&gt;
                                            Dim e2 As Entity = &lt;BR /&gt;
tr.GetObject(item, OpenMode.ForWrite)&lt;BR /&gt;
                                            e2.Color = &lt;BR /&gt;
Color.FromColorIndex(ColorMethod.ByAci, 1)&lt;BR /&gt;
                                            If TypeOf e2 Is BlockReference &lt;BR /&gt;
Then&lt;BR /&gt;
                                                Dim Lcol As New Collection&lt;BR /&gt;
                                                Lcol.Add(e2.ObjectId)&lt;BR /&gt;
                                                RecursiveBlockDefinition(Lcol, &lt;BR /&gt;
BlocksChecked)&lt;BR /&gt;
                                            End If&lt;BR /&gt;
                                        Next&lt;BR /&gt;
                                    End If&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Next&lt;BR /&gt;
                        tr.Commit()&lt;BR /&gt;
                        BT.Dispose()&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub GetBlockSelection(ByRef ColObjID As Collection)&lt;BR /&gt;
        Dim activeDocument As Document = &lt;BR /&gt;
Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim activeDB As Database = activeDocument.Database&lt;BR /&gt;
&lt;BR /&gt;
        Dim ed As Editor = activeDocument.Editor&lt;BR /&gt;
&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
            Using trans As Transaction = &lt;BR /&gt;
db.TransactionManager.StartTransaction()&lt;BR /&gt;
                Dim dwg As Document = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
                Using lock As DocumentLock = dwg.LockDocument&lt;BR /&gt;
&lt;BR /&gt;
                    Dim selectionTypeValue As TypedValue() = New &lt;BR /&gt;
TypedValue(0) {}&lt;BR /&gt;
                    selectionTypeValue.SetValue(New &lt;BR /&gt;
TypedValue(CInt(DxfCode.Start), "INSERT"), 0)&lt;BR /&gt;
&lt;BR /&gt;
                    Dim selectionFilter As New &lt;BR /&gt;
SelectionFilter(selectionTypeValue)&lt;BR /&gt;
&lt;BR /&gt;
                    Dim getSelectionResult As PromptSelectionResult&lt;BR /&gt;
                    getSelectionResult = ed.GetSelection(selectionFilter)&lt;BR /&gt;
&lt;BR /&gt;
                    ' If selection actually contains something&lt;BR /&gt;
                    If getSelectionResult.Status = PromptStatus.OK Then&lt;BR /&gt;
                        Dim selectionSet As SelectionSet = &lt;BR /&gt;
getSelectionResult.Value&lt;BR /&gt;
&lt;BR /&gt;
                        For Each selectedObject As SelectedObject In &lt;BR /&gt;
selectionSet&lt;BR /&gt;
                            If selectedObject IsNot Nothing Then&lt;BR /&gt;
                                Dim selectedEntity As Entity = &lt;BR /&gt;
TryCast(trans.GetObject(selectedObject.ObjectId, OpenMode.ForWrite), Entity)&lt;BR /&gt;
                                If Not &lt;BR /&gt;
ColObjID.Contains(selectedEntity.ObjectId.ToString) Then&lt;BR /&gt;
                                    ColObjID.Add(selectedEntity.ObjectId, &lt;BR /&gt;
selectedEntity.ObjectId.ToString)&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Next&lt;BR /&gt;
&lt;BR /&gt;
                        trans.Commit()&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
&lt;BR /&gt;
        Dim curDoc As Document = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        ' Clear Command Line&lt;BR /&gt;
        curDoc.SendStringToExecute(Chr(27), False, False, False)&lt;BR /&gt;
    End Sub&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;/ARCTICAD&gt;</description>
      <pubDate>Sat, 21 Nov 2009 21:48:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418840#M83993</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-21T21:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nested block?</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418841#M83994</link>
      <description>The code was just an example of how to recursively access all the blocks embedded in another block. &lt;BR /&gt;
&lt;BR /&gt;
By changing the colors of the contents of the block definitions.&lt;BR /&gt;
&lt;BR /&gt;
And your right I can rewrite the code using &lt;BR /&gt;
&lt;BR /&gt;
Dim BTR As BlockTableRecord = tr.GetObject(Col(i), OpenMode.ForWrite)&lt;BR /&gt;
&lt;BR /&gt;
the line wasn't needed.</description>
      <pubDate>Sun, 22 Nov 2009 19:06:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-nested-block/m-p/1418841#M83994</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2009-11-22T19:06:21Z</dc:date>
    </item>
  </channel>
</rss>

