<?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: How to get a collection of all block table records in a file? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159474#M1909</link>
    <description>&lt;PRE&gt;ed.WriteMessage($"\n{btr.Name}");&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I'm checking the docs and I don't see that block table records have 'Name' property...&lt;/P&gt;</description>
    <pubDate>Tue, 19 Nov 2024 08:25:34 GMT</pubDate>
    <dc:creator>OrmArTHe</dc:creator>
    <dc:date>2024-11-19T08:25:34Z</dc:date>
    <item>
      <title>How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13152601#M1905</link>
      <description>&lt;P&gt;How to get a collection of all block table records in a file?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 13:10:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13152601#M1905</guid>
      <dc:creator>OrmArTHe</dc:creator>
      <dc:date>2024-11-15T13:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13152617#M1906</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;Solved&lt;/STRIKE&gt; - by using this method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;TransactionManager.GetAllObjects&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: Not a solution. The method above gets all &lt;STRONG&gt;opened DBObjects in a transaction&lt;/STRONG&gt;.&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 15 Nov 2024 14:35:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13152617#M1906</guid>
      <dc:creator>OrmArTHe</dc:creator>
      <dc:date>2024-11-15T14:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13153234#M1907</link>
      <description>&lt;P&gt;The object you need to open in order to get all BlockTableRecords, is, not surprisingly, BlockTable. You do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using (var tran=[db].TransactionManager.StartTransaction())
{
    var tbl=(BlockTable)tran.GetObject([db].BlockTableId, OpenMode4.ForRead);
    IEnumerable&amp;lt;BlockTableRecord&amp;gt; allRecords=
          tbl.Cast&amp;lt;ObjectId&amp;gt;().Select(id=&amp;gt;(BlockTableRecord)tran.GetObject(id, OpenMode.ForRead);
   // work with the records as needed
   ... ...
   tran.Commit();
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 17:18:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13153234#M1907</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2024-11-15T17:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13153357#M1908</link>
      <description>&lt;LI-CODE lang="csharp"&gt;public static class MyExtensions
{

   public static IEnumerable&amp;lt;T&amp;gt; GetObjects&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;ObjectId&amp;gt; ids,
      Transaction tr,
      OpenMode mode = OpenMode.ForRead)
      where T : DBObject
   {
      if(ids == null)
         throw new ArgumentNullException(nameof(ids));
      if(tr == null)
         throw new ArgumentNullException(nameof(tr));
      RXClass rxclass = RXObject.GetClass(typeof(T));
      foreach(ObjectId id in ids)
      {
         if(id.ObjectClass.IsDerivedFrom(rxclass))
         {
            yield return Unsafe.As&amp;lt;T&amp;gt;(tr.GetObject(id, mode));
         }
      }
   }
   
}

public static class Example
{
   [CommandMethod("LISTBLOCKNAMES")]
   public static void ListBlockNames()
   {
      Document doc = Application.DocumentManager.MdiActiveDocument;
      Editor ed = doc.Editor;
      Database db = doc.Database;
      
      using(var trans = doc.TransactionManager.StartTransaction())
      {
         var blockTable = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
         var ids = blockTable.Cast&amp;lt;ObjectId&amp;gt;();
         var blockTableRecords = ids.GetObjects&amp;lt;BlockTableRecord&amp;gt;(trans);
         foreach(BlockTableRecord btr in blockTableRecords)
         {
            /// btr is only usable up to the call to Commit() below.
            
            ed.WriteMessage($"\n{btr.Name}");
         }
         trans.Commit();
      }
   }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 15 Nov 2024 18:31:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13153357#M1908</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-11-15T18:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159474#M1909</link>
      <description>&lt;PRE&gt;ed.WriteMessage($"\n{btr.Name}");&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I'm checking the docs and I don't see that block table records have 'Name' property...&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 08:25:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159474#M1909</guid>
      <dc:creator>OrmArTHe</dc:creator>
      <dc:date>2024-11-19T08:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159480#M1910</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/16395686"&gt;@OrmArTHe&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;PRE&gt;ed.WriteMessage($"\n{btr.Name}");&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I'm checking the docs and I don't see that block table records have 'Name' property...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;BlockTableRecord derives from SymbolTableRecord which has a &lt;A href="https://help.autodesk.com/view/OARX/2025/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_SymbolTableRecord_Name" target="_blank" rel="noopener"&gt;Name property&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 08:31:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159480#M1910</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-11-19T08:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159509#M1911</link>
      <description>&lt;P&gt;Could you please explain this line:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;var blockTableRecords = ids.GetObjects&amp;lt;BlockTableRecord&amp;gt;(trans);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't seem to find GetObjects method in the docs...&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 08:55:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159509#M1911</guid>
      <dc:creator>OrmArTHe</dc:creator>
      <dc:date>2024-11-19T08:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159552#M1912</link>
      <description>&lt;P&gt;Got it. But GetObject method returns ObjectId... How do I convert it to BlockTableRecord so I can access its Name property?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 09:02:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159552#M1912</guid>
      <dc:creator>OrmArTHe</dc:creator>
      <dc:date>2024-11-19T09:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159583#M1913</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/16395686"&gt;@OrmArTHe&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;Could you please explain this line:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;var blockTableRecords = ids.GetObjects&amp;lt;BlockTableRecord&amp;gt;(trans);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't seem to find GetObjects method in the docs...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;GetObjects&amp;lt;T&amp;gt; method is defined in MyExtensions class.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 09:10:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159583#M1913</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-11-19T09:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159629#M1914</link>
      <description>&lt;P&gt;Here's a method wich return a collection of all the the block table record names.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;private static IEnumerable&amp;lt;string&amp;gt; GetBlockNames(Database db)
{
    using (var tr = new OpenCloseTransaction())
    {
        var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        foreach (ObjectId id in blockTable)
        {
            var btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead);
            yield return btr.Name;
        }
        tr.Commit();
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a testing command:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod("TEST")]
public static void Test()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;

    foreach (string name in GetBlockNames(db))
    {
        ed.WriteMessage($"\n{name}");
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 19 Nov 2024 09:27:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13159629#M1914</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-11-19T09:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13160531#M1915</link>
      <description>&lt;P&gt;This is not directly related to this topic, but I just want to thank&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;for your contributions. Even if a topic is not something I'm directly needing help on, I almost always learn something from your posts. Thank you both!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 15:50:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13160531#M1915</guid>
      <dc:creator>jabowabo</dc:creator>
      <dc:date>2024-11-19T15:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13160545#M1916</link>
      <description>&lt;P&gt;The GetObjects method is in the code that I posted, it is not built into the api. Did you try the code or are you simply looking at it?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 15:55:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13160545#M1916</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-11-19T15:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a collection of all block table records in a file?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13162181#M1917</link>
      <description>&lt;P&gt;Generally, I try to understand it before trying it, but yes, I was too hasty and I missed your 'MyExtensions' Class... Sorry about that... I appreciate your help, your solution if really robust...&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 07:46:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-a-collection-of-all-block-table-records-in-a-file/m-p/13162181#M1917</guid>
      <dc:creator>OrmArTHe</dc:creator>
      <dc:date>2024-11-20T07:46:09Z</dc:date>
    </item>
  </channel>
</rss>

