<?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: Choosing the optimal method in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443674#M6229</link>
    <description>&lt;P&gt;Thank you &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt; for your response. Yes, it seems more logical to not sweep the entire drawing but rather to directly access the specified polyline using the previously stored list of Handle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Dec 2023 14:42:32 GMT</pubDate>
    <dc:creator>youssefGC</dc:creator>
    <dc:date>2023-12-15T14:42:32Z</dc:date>
    <item>
      <title>Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12442462#M6226</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today, I am faced with a choice between two mechanisms. Indeed, I have two programs that interact with each other.&lt;/P&gt;&lt;P&gt;The first program allows the user to draw polylines and stores information in the Xrecord of the entity to mark that this polyline was drawn by my own command.&lt;/P&gt;&lt;P&gt;The second program quantifies the number of entities (polylines) drawn by the first command.&lt;/P&gt;&lt;P&gt;Focusing on the second program, I find two solutions to access the entities:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Method 1:&lt;/STRONG&gt; I can scan all drawn entities and check if the polyline was drawn by the first command by examining the Xrecord field.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Method 2:&lt;/STRONG&gt; In the first command, during the drawing of each polyline, I can store their handle in the Named Object Dictionary (NOD). Then, to quantify the number, I can directly access the dictionary.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Which method seems to be the most effective?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 00:21:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12442462#M6226</guid>
      <dc:creator>youssefGC</dc:creator>
      <dc:date>2023-12-15T00:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12442940#M6227</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Certainly the Method2 which only reads the data stored in a dictionary instead of scaming all the drawn entities. Instead of entities Handle, you can directly store the entities ObjectId as SoftPointer (dxf group 330) to let AutoCAD hande the erased entities (ObjectId.Null).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 07:41:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12442940#M6227</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-12-15T07:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443073#M6228</link>
      <description>&lt;P&gt;What happens if the user copies one of these entities? Have you given consideration to that?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 09:30:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443073#M6228</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2023-12-15T09:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443674#M6229</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt; for your response. Yes, it seems more logical to not sweep the entire drawing but rather to directly access the specified polyline using the previously stored list of Handle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 14:42:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443674#M6229</guid>
      <dc:creator>youssefGC</dc:creator>
      <dc:date>2023-12-15T14:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443696#M6230</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&amp;nbsp; for your remark. Currently, I haven't implemented a solution for the case you've mentioned. However, my idea going forward is to use "ObjectOverrule" to check if the user has copied an entity drawn by the command, and likewise store their new handle.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 15 Dec 2023 14:48:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443696#M6230</guid>
      <dc:creator>youssefGC</dc:creator>
      <dc:date>2023-12-15T14:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443756#M6231</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4114680"&gt;@youssefGC&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;directly access the specified polyline using the previously stored list of Handle.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Storing ObjectIds instead of Handles will avoid you converting Objectid into Handle (with ObjectId.Handle) and converting back Handle into ObjectId (with .TryGetObjectId).&lt;/P&gt;
&lt;P&gt;Here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("SETXRECORD")]
        public static void SetXrecord()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var psr = ed.GetSelection();
            if (psr.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var nod = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                DBDictionary dict;
                if (nod.Contains(dictName))
                {
                    dict = (DBDictionary)tr.GetObject(nod.GetAt(dictName), OpenMode.ForRead);
                }
                else
                {
                    dict = new DBDictionary();
                    tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
                    nod.SetAt(dictName, dict);
                    tr.AddNewlyCreatedDBObject(dict, true);
                }
                Xrecord xrec;
                if (dict.Contains(xrecKey))
                {
                    xrec = (Xrecord)tr.GetObject(dict.GetAt(xrecKey), OpenMode.ForWrite);
                }
                else
                {
                    xrec = new Xrecord();
                    if (!dict.IsWriteEnabled)
                        tr.GetObject(dict.ObjectId, OpenMode.ForRead);
                    dict.SetAt(xrecKey, xrec);
                    tr.AddNewlyCreatedDBObject(xrec, true);
                }
                xrec.Data = new ResultBuffer(
                    psr.Value.GetObjectIds()
                    .Select(id =&amp;gt; new TypedValue(330, id))
                    .ToArray());
                tr.Commit();
            }
        }

        [CommandMethod("GETXRECORD", CommandFlags.Redraw)]
        public static void GetXrecord()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var nod = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                if (!nod.Contains(dictName))
                    return;
                var dict = (DBDictionary)tr.GetObject(nod.GetAt(dictName), OpenMode.ForRead);
                if (!dict.Contains(xrecKey))
                    return;
                var xrec = (Xrecord)tr.GetObject(dict.GetAt(xrecKey), OpenMode.ForRead);
                var data = xrec.Data;
                if (data == null)
                    return;
                var ids = data.AsArray().Select(tv =&amp;gt; (ObjectId)tv.Value).Where(id =&amp;gt; !id.IsNull);
                ed.SetImpliedSelection(ids.ToArray());
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 15:01:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443756#M6231</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-12-15T15:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443872#M6232</link>
      <description>&lt;P&gt;To avoid the problem mentioned by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;, we should revert to using the first method I had outlined in the post. Scanning all entities allows us to identify, using XData/XRecord, the relevant polylines. This appears simpler ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 15:37:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443872#M6232</guid>
      <dc:creator>youssefGC</dc:creator>
      <dc:date>2023-12-15T15:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443917#M6233</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4114680"&gt;@youssefGC&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;To avoid the problem mentioned by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;, we should revert to using the first method I had outlined in the post. Scanning all entities allows us to identify, using XData/XRecord, the relevant polylines. This appears simpler ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, it is simpler and even it should be less efficient, it won't be perceptible depending on the number of entities.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 15:54:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12443917#M6233</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-12-15T15:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing the optimal method</title>
      <link>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12444452#M6234</link>
      <description>&lt;P&gt;I would suggest that you keep your data 'self-contained' if possible, and avoid storing ObjectId/handle references to objects, so that you do not have to deal with all of the possible scenarios where objects can be copied, erased, etc.,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Copying happens not only within the same owner space but also across owner spaces and databases, using BLOCK, WBLOCK, INSERT, etc.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 20:15:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/choosing-the-optimal-method/m-p/12444452#M6234</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2023-12-15T20:15:42Z</dc:date>
    </item>
  </channel>
</rss>

