<?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 ObjectOpenedForModify event in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2821354#M63120</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using AutoCAD (Map) 2010.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Previously I was using the&amp;nbsp;.Net Framework 3.0 and the&amp;nbsp;ObjectOpenedForModify was called upon modifying &amp;nbsp;entities.&lt;/P&gt;&lt;P&gt;After changing to&amp;nbsp;.Net Framework 3.5 the&amp;nbsp;ObjectOpenedForModify is not called anymore.&lt;/P&gt;&lt;P&gt;This is not entirely true, it is called once, only first time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also for&amp;nbsp;ImpliedSelectionChanged, the event is not fired for 3.5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone has the same problems?&lt;/P&gt;&lt;P&gt;Is there a solution (besides using 3.0)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Gertwin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;n.b. I want to use Linq, that is why I changed to 3.5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Nov 2010 15:36:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-11-09T15:36:01Z</dc:date>
    <item>
      <title>ObjectOpenedForModify event</title>
      <link>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2821354#M63120</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using AutoCAD (Map) 2010.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Previously I was using the&amp;nbsp;.Net Framework 3.0 and the&amp;nbsp;ObjectOpenedForModify was called upon modifying &amp;nbsp;entities.&lt;/P&gt;&lt;P&gt;After changing to&amp;nbsp;.Net Framework 3.5 the&amp;nbsp;ObjectOpenedForModify is not called anymore.&lt;/P&gt;&lt;P&gt;This is not entirely true, it is called once, only first time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also for&amp;nbsp;ImpliedSelectionChanged, the event is not fired for 3.5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone has the same problems?&lt;/P&gt;&lt;P&gt;Is there a solution (besides using 3.0)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Gertwin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;n.b. I want to use Linq, that is why I changed to 3.5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2010 15:36:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2821354#M63120</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-09T15:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: ObjectOpenedForModify event</title>
      <link>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2821606#M63121</link>
      <description>&lt;P&gt;I do not have access to Acad2010, but I tried with Acad2009 and Acad2011 (both are AcadMap) with .NET3.5 (VS2008). The event fires as expected. This is the code (I added some comments regarding the event with relevant lines of code):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(ObjectOpenedEvent.MyCommand))]

namespace ObjectOpenedEvent
{
    public class MyCommand 
    {
        [CommandMethod("MyCommand")]
        public static void RunThisMethod()
        {
            Document dwg = Autodesk.AutoCAD.ApplicationServices.
                Application.DocumentManager.MdiActiveDocument;

            Editor ed = dwg.Editor;

            dwg.Database.ObjectOpenedForModify+=
                new ObjectEventHandler(Database_ObjectOpenedForModify);

            bool go = true;
            while (go)
            {
                PromptEntityOptions opt = 
                    new PromptEntityOptions("\nPick an entity:");
                PromptEntityResult res = ed.GetEntity(opt);

                if (res.Status == PromptStatus.OK)
                {
                    ObjectId entId = res.ObjectId;

                    ModifyObject(dwg.Database, entId);
                }
                else
                {
                    go = false;
                }
            }

            dwg.Database.ObjectOpenedForModify -= Database_ObjectOpenedForModify;

            ed.WriteMessage("\nMyCommand executed.");
        }

        private static void Database_ObjectOpenedForModify(object sender, ObjectEventArgs e)
        {
            Document dwg = Autodesk.AutoCAD.ApplicationServices.
                Application.DocumentManager.MdiActiveDocument;

            dwg.Editor.WriteMessage(
                "\nObjectOpenedForModify event being handled on this object: {0}", 
                e.DBObject.ObjectId.ToString());
        }

        private static void ModifyObject(Database db, ObjectId entId)
        {
            using (Transaction tran = db.TransactionManager.StartTransaction())
            {
                Entity ent = (Entity)tran.GetObject(entId, OpenMode.ForRead);

                //This line does not trigger the envent
                ent.UpgradeOpen();

                //The event only triggered when the first line of code
                //that modified the entity is to be executed.
                //That is, event fires first that the ColorIndex is changed
                ent.ColorIndex = 1;

                //The event only fires once per entity being opened.
                //Thus this line does not trigger the event
                ent.Layer = "Layer1";

                ent.DowngradeOpen();

                tran.Commit();
            }
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the Acad's text window, after picking&amp;nbsp;3 entities&amp;nbsp;(the code prints text inside the event handler, so we know the event fires):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Command: mycommand&lt;BR /&gt;Pick an entity:&lt;BR /&gt;ObjectOpenedForModify event being handled on this object: (2129323136)&lt;BR /&gt;Pick an entity:&lt;BR /&gt;ObjectOpenedForModify event being handled on this object: (2129323144)&lt;BR /&gt;Pick an entity:&lt;BR /&gt;ObjectOpenedForModify event being handled on this object: (2129323152)&lt;BR /&gt;Pick an entity: *Cancel*&lt;BR /&gt;MyCommand executed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did not try Document.ImpliedSelectionChanged event, though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2010 18:43:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2821606#M63121</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2010-11-09T18:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: ObjectOpenedForModify event</title>
      <link>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2824466#M63122</link>
      <description>&lt;P&gt;Hi Norman,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;Your code works as expected, so I have to review my own code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Gertwin&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2010 07:16:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2824466#M63122</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-12T07:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: ObjectOpenedForModify event</title>
      <link>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2824596#M63123</link>
      <description>&lt;P&gt;FYI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An exception was &amp;nbsp;thrown from within the event handler.&lt;/P&gt;&lt;P&gt;This causes the event not to fire anymore.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This line was the cause of the exception:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;foreach (KeyValuePair&amp;lt;string, AttributeClass&amp;gt; key_value_pair in attributes.OrderBy(key =&amp;gt; key.Value))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I needed to implement the IComparable interface in&amp;nbsp;AttributeClass.&lt;/P&gt;&lt;P&gt;After that it works as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gertwin&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2010 13:11:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/objectopenedformodify-event/m-p/2824596#M63123</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-12T13:11:14Z</dc:date>
    </item>
  </channel>
</rss>

