<?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: Identify if a block is nested? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/identify-if-a-block-is-nested/m-p/11078462#M13302</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9590272"&gt;@js75CAD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;.... I am struggling to identify only those blocks directly inserted ....&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If it's an option for you, AutoLisp can do that, with Blocks that are not dynamic.&amp;nbsp; This will "see" those Inserted directly, but not those that are nested in other Blocks/Xrefs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" color="#000000"&gt;&lt;STRONG&gt;(ssget "_X" '((2 . "YourBlockName")))&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 02 Apr 2022 12:12:48 GMT</pubDate>
    <dc:creator>Kent1Cooper</dc:creator>
    <dc:date>2022-04-02T12:12:48Z</dc:date>
    <item>
      <title>Identify if a block is nested?</title>
      <link>https://forums.autodesk.com/t5/net-forum/identify-if-a-block-is-nested/m-p/11077931#M13300</link>
      <description>&lt;P&gt;I am trying to iterate the block table records of a particular block, but I put this block in my current drawing and both xreferences and nested xreferences contain it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is this, but I am struggling to identify only those blocks directly inserted into model space. I know why it is doing what it is doing, because they all belong in the block table, but how do I stop it from accessing anything that is nested?&lt;/P&gt;&lt;LI-CODE lang="general"&gt;&amp;lt;CommandMethod("UDC_PhaseConnectionReport")&amp;gt; Public Sub UDC_PhaseConnectionReport()
        doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        db = HostApplicationServices.WorkingDatabase
        ed = doc.Editor

        Dim phList As New List(Of Phasedata)

        Try
            Using tr As Transaction = db.TransactionManager.StartTransaction
                Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)

                If Not bt.Has("phase") Then
                    Return
                Else
                    Dim btr As BlockTableRecord = Nothing
                    Dim btrIDs As ObjectIdCollection = Nothing

                    btr = tr.GetObject(bt("phase"), OpenMode.ForRead)
                    btrIDs = Nothing
                    btrIDs = btr.GetBlockReferenceIds(True, False)

                    ' Go through each phase block and check ju=st like the other one..
                    For Each id As ObjectId In btrIDs
                        If Not id.IsEffectivelyErased Then

                            Dim oBr As BlockReference = TryCast(tr.GetObject(id, OpenMode.ForWrite, False, True), BlockReference)

                            ' Check if it is nested (dependent?)
                            Dim chkbtr As BlockTableRecord = CType(tr.GetObject(oBr.OwnerId, OpenMode.ForWrite), BlockTableRecord)

                            If Not chkbtr.IsDependent Then
                                ' This isn't stopping it...
                                Dim datts As New Dictionary(Of String, String)
                                datts = oBr.GetAttributesValues
                                iPt = oBr.Position

                                Dim strStn As String = "NaN"
                                Dim Sid As String = "NaN"
                                Dim strLot As String = "NaN"
                                Dim strTx As String = "NaN"
                                Dim strPh As String = "NaN"

                                If datts.ContainsKey("STN") Then If Not String.IsNullOrEmpty(datts.Item("STN")) Then strStn = datts.Item("STN")

                                If datts.ContainsKey("ID") Then If Not String.IsNullOrEmpty(datts.Item("ID")) Then Sid = datts.Item("ID")

                                If datts.ContainsKey("LOT") Then If Not String.IsNullOrEmpty(datts.Item("LOT")) Then strLot = datts.Item("LOT")

                                If datts.ContainsKey("TX") Then If Not String.IsNullOrEmpty(datts.Item("TX")) Then strTx = datts.Item("TX")

                                If datts.ContainsKey("P1") Then If Not String.IsNullOrEmpty(datts.Item("P1")) Then strPh = datts.Item("P1")

                                Dim phd As New Phasedata(strLot, strPh, Sid, strStn, strTx)
                                phList.Add(phd)
                            End If
                        End If
                    Next
                End If

                '' Display the data..
                phList = phList.OrderBy(Function(m) m.lot).ToList

                For Each l In phList
                    ed.WriteMessage(vbLf &amp;amp; "{0} {1}, {2}", l.lot.PadRight(10), l.ph.PadRight(10), l.sID)
                Next

                tr.Commit()
            End Using

        Catch ex As Exception
            MsgBoxWithLineNumber(ex.Message)
        End Try

    End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is anyone able to please help? I know I could just get all the ones in model space with a editor selection, but I am really trying to learn how to navigate the AutoCAD database and understand the relationship between the block table and its records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 02:23:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/identify-if-a-block-is-nested/m-p/11077931#M13300</guid>
      <dc:creator>js75CAD</dc:creator>
      <dc:date>2022-04-02T02:23:57Z</dc:date>
    </item>
    <item>
      <title>Betreff: Identify if a block is nested?</title>
      <link>https://forums.autodesk.com/t5/net-forum/identify-if-a-block-is-nested/m-p/11078153#M13301</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a Block is never nested, just Blockreference can be nested in a Blockefinition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You posted in AutoCAD board, this isn't the best place for your question -&lt;/P&gt;
&lt;P&gt;You should ask in a board for programmong and the API you use (.net?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/autocad/ct-p/8" target="_blank"&gt;https://forums.autodesk.com/t5/autocad/ct-p/8&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 07:05:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/identify-if-a-block-is-nested/m-p/11078153#M13301</guid>
      <dc:creator>cadffm</dc:creator>
      <dc:date>2022-04-02T07:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Identify if a block is nested?</title>
      <link>https://forums.autodesk.com/t5/net-forum/identify-if-a-block-is-nested/m-p/11078462#M13302</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9590272"&gt;@js75CAD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;.... I am struggling to identify only those blocks directly inserted ....&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If it's an option for you, AutoLisp can do that, with Blocks that are not dynamic.&amp;nbsp; This will "see" those Inserted directly, but not those that are nested in other Blocks/Xrefs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" color="#000000"&gt;&lt;STRONG&gt;(ssget "_X" '((2 . "YourBlockName")))&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 12:12:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/identify-if-a-block-is-nested/m-p/11078462#M13302</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2022-04-02T12:12:48Z</dc:date>
    </item>
  </channel>
</rss>

