<?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 use C# to traverse all objects in DWG? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647223#M18971</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027"&gt;@Alexander.Rivilis&lt;/a&gt;&amp;nbsp;&amp;nbsp;From the tests I did, the BlockTable handle is always 1 &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jul 2020 16:39:14 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2020-07-21T16:39:14Z</dc:date>
    <item>
      <title>How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9646088#M18967</link>
      <description>&lt;P&gt;I need to traverse all objects, and then get the data type of each object. I am using .net api for the first time, I have used objectARX before.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 08:07:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9646088#M18967</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2020-07-21T08:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9646131#M18968</link>
      <description>&lt;P&gt;All objects in ModelSpace/PaperSpace or all objects in Database?&lt;/P&gt;
&lt;P&gt;First case is very simple. Second case is more complicated.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 08:32:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9646131#M18968</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2020-07-21T08:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647141#M18969</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027"&gt;@Alexander.Rivilis&lt;/a&gt; Not so complicated...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example for both: all objects and all entities in spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

using System.Collections.Generic;

using AcAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace GetAllObjectsInDatabase
{
    public class Commands
    {
        [CommandMethod("TEST1")]
        public static void Test1()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            foreach (var item in GetAllObjects(db))
            {
                ed.WriteMessage($"\n{item.Key.Handle,-6} {item.Value}");
            }
        }


        [CommandMethod("TEST2")]
        public static void Test2()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            foreach (var item in GetAllEntities(db))
            {
                ed.WriteMessage($"\n{item.Key.Handle,-6} {item.Value}");
            }
        }

        static Dictionary&amp;lt;ObjectId, string&amp;gt; GetAllObjects(Database db)
        {
            var dict = new Dictionary&amp;lt;ObjectId, string&amp;gt;();
            for (long i = 0; i &amp;lt; db.Handseed.Value; i++)
            {
                if (db.TryGetObjectId(new Handle(i), out ObjectId id))
                    dict.Add(id, id.ObjectClass.Name);
            }
            return dict;
        }

        static Dictionary&amp;lt;ObjectId, string&amp;gt; GetAllEntities(Database db)
        {
            var dict = new Dictionary&amp;lt;ObjectId, string&amp;gt;();
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                foreach (var btrId in bt)
                {
                    var btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
                    if (btr.IsLayout)
                    {
                        foreach (var id in btr)
                        {
                            dict.Add(id, id.ObjectClass.Name);
                        }
                    }
                }
                tr.Commit();
            }
            return dict;
        }
    }
}
&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:07:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647141#M18969</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-07-21T16:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647168#M18970</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you change&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;for (long i = 0; i &amp;lt; db.Handseed.Value; i++)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;for (long i = db.BlockTableId.Handle.Value; i &amp;lt; db.Handseed.Value; i++)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;it will be more useful. IMHO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:18:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647168#M18970</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2020-07-21T16:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647223#M18971</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027"&gt;@Alexander.Rivilis&lt;/a&gt;&amp;nbsp;&amp;nbsp;From the tests I did, the BlockTable handle is always 1 &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 16:39:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647223#M18971</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-07-21T16:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647287#M18972</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027"&gt;@Alexander.Rivilis&lt;/a&gt;&amp;nbsp;&amp;nbsp;From the tests I did, the BlockTable handle is always 1 &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have a problem with some dwg-files, posted to me, which start handle is very-very big value.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 17:10:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647287#M18972</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2020-07-21T17:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647303#M18973</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027"&gt;@Alexander.Rivilis&lt;/a&gt;&amp;nbsp;&amp;nbsp;You're right, your silution is more robust and efficient.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 17:19:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9647303#M18973</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-07-21T17:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9648135#M18974</link>
      <description>&lt;P&gt;I can't distinguish between all objects in the model space and all objects in the database, I think they are the same. I want to get all the graphics-related data in the drawing. My job is to use another graphics engine to redraw these data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I remember you, you helped me many times in the objectARX forum, thank you.&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 01:39:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9648135#M18974</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2020-07-22T01:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9648137#M18975</link>
      <description>&lt;P&gt;I am learning your code, thank you&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 01:40:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9648137#M18975</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2020-07-22T01:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use C# to traverse all objects in DWG?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9648527#M18976</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8108635"&gt;@zhengyunyang2019&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I can't distinguish between all objects in the model space and all objects in the database, I think they are the same...&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. And if you check &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; code you can find big difference.&lt;/P&gt;
&lt;P&gt;For example, layer, block, layout, etc. also objects but not a part of model space.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 08:31:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-use-c-to-traverse-all-objects-in-dwg/m-p/9648527#M18976</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2020-07-22T08:31:01Z</dc:date>
    </item>
  </channel>
</rss>

