<?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: access entity event after transaction in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9355013#M20243</link>
    <description>&lt;P&gt;And if you run a 'step by step' after the break point does it reach:&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;pline.Modified += Pline_Modified;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Mar 2020 11:16:11 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2020-03-03T11:16:11Z</dc:date>
    <item>
      <title>access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9330736#M20231</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to programm a command with events. It should run like this:&lt;/P&gt;&lt;P&gt;First I make a prompt to pick a polyline. Then I put a event on this polyline, for example modified.&lt;/P&gt;&lt;P&gt;And when I modify the polyline the area of the polyline should be shown in a message box.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can this event get triggered after the transaction has been ended?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 13:22:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9330736#M20231</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-20T13:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9331591#M20232</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

using System;

using AcCoreAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace ObjectModifiedEventSample
{
    public class Commands
    {
        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = AcCoreAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var options = new PromptEntityOptions("\nSelect Polyline: ");
            options.SetRejectMessage("\nSelected object is not a Polyline.");
            options.AddAllowedClass(typeof(Polyline), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var pline = (Polyline)tr.GetObject(result.ObjectId, OpenMode.ForRead);
                pline.Modified += Pline_Modified;
                tr.Commit();
            }
        }

        private static void Pline_Modified(object sender, EventArgs e)
        {
            var pline = (Polyline)sender;
            AcCoreAp.ShowAlertDialog($"Area = {pline.Area}");
        }
    }
}
&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Feb 2020 18:21:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9331591#M20232</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-02-20T18:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9332753#M20233</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;for the example, that's it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I save and close the document with the polyline and open it afterwards the event does not exist anymore. So I have to call the command again with every session.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to programm it that the event is saved and i do not have to call the command everytime again?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 08:12:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9332753#M20233</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-21T08:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9333721#M20234</link>
      <description>&lt;P&gt;You have to set some 'marker' to the watched polylines (xdata or extension dictionary xrecord) or store the polyline handles in a drawing dictionary so that you're able to retrieve these polylines to reset their event handlers.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 15:32:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9333721#M20234</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-02-21T15:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9341956#M20235</link>
      <description>&lt;P&gt;Do you have a little example how this should look like?&lt;/P&gt;&lt;P&gt;I can't imagine right now how to handle the attached xdata.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 08:46:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9341956#M20235</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-26T08:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9341995#M20236</link>
      <description>&lt;P&gt;Here's an example using a named dictionary to store the 'watched polylines' identifiers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The WatchedPolyline class&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

using System;
using System.Linq;

using AcCoreAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace ObjectModifiedEventSample
{
    class WatchedPolyline
    {
        static string dictName = "GILE_MODIFIED_EVENT";
        static string xrecName =&amp;gt; "WatchedPlines";

        public static void Pline_Modified(object sender, EventArgs e)
        {
            var pline = (Polyline)sender;
            AcCoreAp.ShowAlertDialog($"Area = {pline.Area}");
        }

        public static void AddPolyline(Transaction tr, Polyline pline)
        {
            var db = pline.Database;
            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
            {
                tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
                dict = new DBDictionary();
                NOD.SetAt(dictName, dict);
                tr.AddNewlyCreatedDBObject(dict, true);
            }
            Xrecord xrec;
            ResultBuffer data;
            if (dict.Contains(xrecName))
            {
                xrec = (Xrecord)tr.GetObject(dict.GetAt(xrecName), OpenMode.ForWrite);
                data = xrec.Data;
                if (!data.Cast&amp;lt;TypedValue&amp;gt;().Any(tv =&amp;gt; tv.Value.Equals(pline.ObjectId)))
                {
                    data.Add(new TypedValue(330, pline.ObjectId));
                    pline.Modified += Pline_Modified;
                }
            }
            else
            {
                xrec = new Xrecord();
                dict.SetAt(xrecName, xrec);
                tr.AddNewlyCreatedDBObject(xrec, true);
                data = new ResultBuffer(new TypedValue(330, pline.ObjectId));
                pline.Modified += Pline_Modified;
            }
            xrec.Data = data;
        }

        public static void UpdatePolylines(Document doc)
        {
            var db = doc.Database;
            using (doc.LockDocument())
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var NOD = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                if (NOD.Contains(dictName))
                {
                    var dict = (DBDictionary)tr.GetObject(NOD.GetAt(dictName), OpenMode.ForRead);
                    if (dict.Contains(xrecName))
                    {
                        var xrec = (Xrecord)tr.GetObject(dict.GetAt(xrecName), OpenMode.ForWrite);
                        var data = new ResultBuffer();
                        foreach (TypedValue typedValue in xrec.Data)
                        {
                            var id = (ObjectId)typedValue.Value;
                            if (id.IsErased)
                                continue;
                            var pline = (Polyline)tr.GetObject(id, OpenMode.ForRead);
                            pline.Modified += Pline_Modified;
                            data.Add(typedValue);
                        }
                        xrec.Data = data;
                    }
                }
                tr.Commit();
            }
        }
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Initialization class&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

using System;

using AcCoreAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace ObjectModifiedEventSample
{
    public class Initialization : IExtensionApplication
    {
        public void Initialize()
        {
            AcCoreAp.Idle += OnIdle;
        }

        private void OnIdle(object sender, EventArgs e)
        {
            var docs = AcCoreAp.DocumentManager;
            var acDoc = docs.MdiActiveDocument;
            if (acDoc != null)
            {
                AcCoreAp.Idle -= OnIdle;
                foreach (Document doc in docs)
                {
                    WatchedPolyline.UpdatePolylines(doc);
                }
                docs.DocumentCreated += Docs_DocumentCreated;
            }
        }

        public void Terminate()
        { }

        private void Docs_DocumentCreated(object sender, DocumentCollectionEventArgs e) =&amp;gt;
            WatchedPolyline.UpdatePolylines(e.Document);
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Commands class&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

using AcCoreAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace ObjectModifiedEventSample
{
    public class Commands
    {
        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = AcCoreAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var options = new PromptEntityOptions("\nSelect Polyline: ");
            options.SetRejectMessage("\nSelected object is not a Polyline.");
            options.AddAllowedClass(typeof(Polyline), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var pline = (Polyline)tr.GetObject(result.ObjectId, OpenMode.ForRead);
                WatchedPolyline.AddPolyline(tr, pline);
                tr.Commit();
            }
        }
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 08:58:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9341995#M20236</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-02-26T08:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9343053#M20237</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&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;Since I have this example in my .dll my BricsCAD does not really run when I load the .dll file. Then it is very slow that you can't work with it.&lt;/P&gt;&lt;P&gt;I think it is because of the initialization class. When I comment this out it runs normal.&lt;/P&gt;&lt;P&gt;Do you know how I can solve this?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 15:35:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9343053#M20237</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-26T15:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9343608#M20238</link>
      <description>&lt;P&gt;This is probably dur to BricsCAD because I do not notice such problem with AutoCAD.&lt;/P&gt;
&lt;P&gt;The initialization class is required to register the DocumentCreated and run UpdatePolylines on each already opened document when the application is loaded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try to avoid the Idle event handling (not tested).&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

using System;

using AcCoreAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace ObjectModifiedEventSample
{
    public class Initialization : IExtensionApplication
    {
        public void Initialize()
        {
            var docs = AcCoreAp.DocumentManager;
            foreach (Document doc in docs)
            {
                WatchedPolyline.UpdatePolylines(doc);
            }
            docs.DocumentCreated += Docs_DocumentCreated;
        }

        public void Terminate()
        { }

        private void Docs_DocumentCreated(object sender, DocumentCollectionEventArgs e) =&amp;gt;
            WatchedPolyline.UpdatePolylines(e.Document);
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 18:30:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9343608#M20238</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-02-26T18:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9352053#M20239</link>
      <description>&lt;P&gt;Thank you. With this initialization part it runs well when I use the command.&lt;/P&gt;&lt;P&gt;But when I safe, close and reopen the document the event is not safed...&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 08:14:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9352053#M20239</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-02T08:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9352089#M20240</link>
      <description>&lt;P&gt;And I tried the original initialization class in c# now and this runs. (Because first I only tried in VB.NET)&lt;/P&gt;&lt;P&gt;But it is the same problem that the event is not safed...&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 08:40:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9352089#M20240</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-02T08:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9352411#M20241</link>
      <description>&lt;P&gt;When the application is loaded, the Initialize method is run and the event handlers should be add to the 'watched polylines' of every opened drawing, idem for each later created document because of the DocumentCreated handler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try putting a breakpoint at the beginning of the WatchedPolyline.UpdatePolylines() method, the execution should stop for each already opened document when the application is loaded and for each later created document.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 12:14:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9352411#M20241</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-03-02T12:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9354905#M20242</link>
      <description>&lt;P&gt;Yes, when I put a breakpoint to this point it runs like in your description.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 10:11:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9354905#M20242</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-03T10:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9355013#M20243</link>
      <description>&lt;P&gt;And if you run a 'step by step' after the break point does it reach:&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;pline.Modified += Pline_Modified;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 11:16:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9355013#M20243</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-03-03T11:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9355470#M20244</link>
      <description>&lt;P&gt;When I start debugging and open the application it skips that line because it does not get in this foreach loop.&lt;/P&gt;&lt;P&gt;When I draw a polyline and make the TEST command it reaches your line in the AddPolyline method.&lt;/P&gt;&lt;P&gt;When I save, close and reopen the drawing it reaches the line in UpdatePolylines method.&lt;/P&gt;&lt;P&gt;But when I step foreward and get back to the drawing the event does no more work.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 14:16:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9355470#M20244</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-03T14:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9355831#M20245</link>
      <description>&lt;P&gt;I'm afraid I cannot help you further.&lt;/P&gt;
&lt;P&gt;The code I purposed works as expected with AutoCAD.&lt;/P&gt;
&lt;P&gt;May be an issue with BricsCAD...&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 16:30:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9355831#M20245</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-03-03T16:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: access entity event after transaction</title>
      <link>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9357027#M20246</link>
      <description>&lt;P&gt;Too bad.&lt;/P&gt;&lt;P&gt;But thanks a lot for your efforts!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 07:40:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/access-entity-event-after-transaction/m-p/9357027#M20246</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-04T07:40:48Z</dc:date>
    </item>
  </channel>
</rss>

