<?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 Find list of blocks in drawing but no instance visable in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014172#M25878</link>
    <description>I am looking for a VB.net way to search for a blocks name in a drawing where the block current has no visable instance. For example, if I have a block named "temp" that has previously been inserted into the drawing, but has been deleted, but not purged, how can I find this block by its name or other means?&lt;BR /&gt;&lt;BR /&gt;Please let me know your thoughts.</description>
    <pubDate>Sun, 20 May 2018 17:35:28 GMT</pubDate>
    <dc:creator>conveyor1</dc:creator>
    <dc:date>2018-05-20T17:35:28Z</dc:date>
    <item>
      <title>Find list of blocks in drawing but no instance visable</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014172#M25878</link>
      <description>I am looking for a VB.net way to search for a blocks name in a drawing where the block current has no visable instance. For example, if I have a block named "temp" that has previously been inserted into the drawing, but has been deleted, but not purged, how can I find this block by its name or other means?&lt;BR /&gt;&lt;BR /&gt;Please let me know your thoughts.</description>
      <pubDate>Sun, 20 May 2018 17:35:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014172#M25878</guid>
      <dc:creator>conveyor1</dc:creator>
      <dc:date>2018-05-20T17:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Find list of blocks in drawing but no instance visable</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014213#M25879</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_Database_Purge_ObjectIdCollection" target="_blank"&gt;Database.Purge(&lt;/A&gt;) method to ge unreferenced blocks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public List&amp;lt;string&amp;gt; GetUnreferencedBlockNames(Database db)
        {
            var result = new List&amp;lt;string&amp;gt;();
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                ObjectIdCollection blockIds = new ObjectIdCollection();
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                foreach (ObjectId id in bt)
                {
                    blockIds.Add(id);
                }
                db.Purge(blockIds);
                foreach (ObjectId id in blockIds)
                {
                    var block = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                    result.Add(block.Name);
                }
            }
            return result;
        }&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 May 2018 18:54:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014213#M25879</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-05-20T18:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find list of blocks in drawing but no instance visable</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014219#M25880</link>
      <description>&lt;P&gt;Another way using the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_BlockTableRecord_GetBlockReferenceIds__MarshalAsUnmanagedType_U1__bool__MarshalAsUnmanagedType_U1__bool" target="_blank"&gt;BlockTableRecord.GetBlockReferenceIds()&lt;/A&gt; method.&lt;/P&gt;
&lt;P&gt;This one does not care if the block definition is hard referenced by some other object than a block reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public List&amp;lt;string&amp;gt; GetUnreferencedblockNames(Database db)
        {
            var result = new List&amp;lt;string&amp;gt;();
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                foreach (ObjectId id in bt)
                {
                    var btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead);
                    if (!btr.IsLayout &amp;amp;&amp;amp; btr.GetBlockReferenceIds(true, true).Count == 0)
                    {
                        result.Add(btr.Name);
                    }
                }
            }
            return result;
        }&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 May 2018 19:07:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014219#M25880</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-05-20T19:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: Find list of blocks in drawing but no instance visable</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014537#M25881</link>
      <description>&lt;P&gt;You can use the BlockTable's indexer to find the ObjectId of a BlockTableRecord given the block's name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the BlockTable's Has() method to find out if a block with the given name is defined in a drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1179727"&gt;@conveyor1&lt;/a&gt;wrote:&lt;BR /&gt;I am looking for a VB.net way to search for a blocks name in a drawing where the block current has no visable instance. For example, if I have a block named "temp" that has previously been inserted into the drawing, but has been deleted, but not purged, how can I find this block by its name or other means?&lt;BR /&gt;&lt;BR /&gt;Please let me know your thoughts.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 04:47:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8014537#M25881</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-05-21T04:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: Find list of blocks in drawing but no instance visable</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8016381#M25882</link>
      <description>&lt;P&gt;Here is what I used to get the required result. (TextBoxForm32 has the name of the Block).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;' Check if Block Exists&lt;BR /&gt;Dim mydwg As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;Dim mytransMan As Database = mydwg.Database&lt;BR /&gt;' Get the current document and database, and start a transaction&lt;BR /&gt;Using mytrans As Transaction = mytransMan.TransactionManager.StartTransaction()&lt;BR /&gt;' Open the Block table record for read&lt;BR /&gt;Dim mybt As BlockTable&lt;BR /&gt;mybt = mytrans.GetObject(mytransMan.BlockTableId, OpenMode.ForRead)&lt;BR /&gt;If (mybt.Has(TextBoxForm32)) Then&lt;BR /&gt;Else&lt;BR /&gt;Form_Error = True&lt;BR /&gt;MsgBox("Load the Drawing Template for dot Net")&lt;BR /&gt;End If&lt;BR /&gt;' Dispose of the transaction&lt;BR /&gt;mytrans.Dispose()&lt;BR /&gt;End Using&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 20:41:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-list-of-blocks-in-drawing-but-no-instance-visable/m-p/8016381#M25882</guid>
      <dc:creator>conveyor1</dc:creator>
      <dc:date>2018-05-21T20:41:04Z</dc:date>
    </item>
  </channel>
</rss>

