<?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 MDIActiveDocument and DocumentActivated in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3629886#M53179</link>
    <description>&lt;P&gt;I have set a handler for the DocumentActivated event message but it doesn't get called when I set the MDIActiveDocument on the document manager object. It gets called when I swich windows, but not when the active document is initially set. Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[CommandMethod("IFX_NEW_ASSEMBLY", CommandFlags.Session)]&lt;/P&gt;&lt;P&gt;void NewAssembly()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document doc = Application.DocumentManagerr.Add("");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Application.DocumentManager.MDIActiveDocument = doc;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should the DocumentActivated event be fired with the above code. P.S. I am positive the event handler is hooked up correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Mike B&lt;/P&gt;</description>
    <pubDate>Fri, 21 Sep 2012 20:16:41 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-09-21T20:16:41Z</dc:date>
    <item>
      <title>MDIActiveDocument and DocumentActivated</title>
      <link>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3629886#M53179</link>
      <description>&lt;P&gt;I have set a handler for the DocumentActivated event message but it doesn't get called when I set the MDIActiveDocument on the document manager object. It gets called when I swich windows, but not when the active document is initially set. Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[CommandMethod("IFX_NEW_ASSEMBLY", CommandFlags.Session)]&lt;/P&gt;&lt;P&gt;void NewAssembly()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document doc = Application.DocumentManagerr.Add("");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Application.DocumentManager.MDIActiveDocument = doc;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should the DocumentActivated event be fired with the above code. P.S. I am positive the event handler is hooked up correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Mike B&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2012 20:16:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3629886#M53179</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-09-21T20:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: MDIActiveDocument and DocumentActivated</title>
      <link>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3629994#M53180</link>
      <description>&lt;P&gt;How do you wire up the DocumentActivated event?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following code works for me:&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.Runtime;

[assembly: CommandClass(typeof(DocumentActevatedEvent.MyCommands))]
[assembly: ExtensionApplication(typeof(DocumentActevatedEvent.MyCommands))]

namespace DocumentActevatedEvent
{
    public class MyCommands : IExtensionApplication
    {
        #region IExtensionApplication Members

        public void Initialize()
        {
            Document dwg = Application.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            try
            {
                ed.WriteMessage("\nInitializing...");

                Application.DocumentManager.DocumentActivated += DocumentManager_DocumentActivated;

                ed.WriteMessage("completed.");
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("failed:\n");
                ed.WriteMessage(ex.Message);
            }

            Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
        }

        private void DocumentManager_DocumentActivated(object sender, DocumentCollectionEventArgs e)
        {
            e.Document.Editor.WriteMessage("\n{0} activated.", e.Document.Name);
            Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
        }

        public void Terminate()
        {

        }

        #endregion

        [CommandMethod("AddNewDoc", CommandFlags.Session)]
        public static void RunMyCommand()
        {
            Document dwg = Application.DocumentManager.Add(null);
            Application.DocumentManager.MdiActiveDocument=dwg;

        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I use AutoCAD 2012 and VS2010.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, the second line of code in the CommandMethod:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Application.Documentmanager.MdiActiveDocument=dwg;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is not needed. When a new document is added, AutoCAD automatically set it as the active document. That is, the DocumentActivated event is triggered at the end of Add() method, not by the code App...MdiActiveDocument=dwg;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2012 21:31:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3629994#M53180</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2012-09-21T21:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: MDIActiveDocument and DocumentActivated</title>
      <link>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3630234#M53181</link>
      <description>&lt;P&gt;No different than your code except I have an AppData class that manages custom DocData class collection. The AppData has an Initialization method where the wiring is done. This gets called by the extension class initialization.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I removed the assignment and it seems to fire now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Mike&lt;/P&gt;</description>
      <pubDate>Sat, 22 Sep 2012 13:52:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3630234#M53181</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-09-22T13:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: MDIActiveDocument and DocumentActivated</title>
      <link>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3804453#M53182</link>
      <description>&lt;P&gt;Is anyone else having this same dwg activate problem, with R2013? I have a large project that has stopped working since the 2013 upgrade.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have substituted the new call DocumentCollectionExtension.Add(acDocMgr,templatefile) - and I am using CommandFlags.Session - but the document is still not activated until the command has finished.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've distilled it down to a couple of simple test commands:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    &amp;lt;CommandMethod("NewDrawing", CommandFlags.Session)&amp;gt; _
    Public Sub NewDrawing()
        'Create a new drawing and activate it

        Dim strTemplatePath As String = "acad-test.dwt" 'from support path

        Dim acDocMgr As DocumentCollection = Application.DocumentManager
        Dim acDoc As Document = DocumentCollectionExtension.Add(acDocMgr, _
                                            strTemplatePath)
        'the above line should activate the new added document but doesn't
        'acDocMgr.MdiActiveDocument = acDoc  'THIS LINE DOES NOT MAKE THE DWG ACTIVE
        Application.ShowAlertDialog("Active document is now " &amp;amp; acDocMgr.MdiActiveDocument.Name)
        'this stills shows drawing1 until after the command finishes

    End Sub


    &amp;lt;CommandMethod("ActiveDrawing", CommandFlags.Session)&amp;gt; _
    Public Sub ActiveDrawing()
        'Show which drawing is currently active

        Dim acDocMgr As DocumentCollection = Application.DocumentManager

        Application.ShowAlertDialog("Active document is now " &amp;amp; acDocMgr.MdiActiveDocument.Name)
        'this shows Drawing2 if this is run after the NewDrawing command has finished

    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any updated sample code for 2013 anywhere? I could not get the code in the 2013 Dev Guide&amp;nbsp;(&lt;A href="http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-4E1AAFA9-740E-4097-800C-CAED09CDFF12.htm,topicNumber=d30e712496" target="_blank" title="AutoCAD 2013 Developer's Guide: lock &amp;amp; unlock a document"&gt;here&lt;/A&gt;, search for "LockDoc") to compile as it has not been updated to use the new DocumentCollectionExtension methods. I have substituted the new method calls into that code but still have the activation problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2013 04:30:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/3804453#M53182</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-03-14T04:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: MDIActiveDocument and DocumentActivated</title>
      <link>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/5504573#M53184</link>
      <description>&lt;P&gt;"Is there any updated sample code for 2013 anywhere? I could not get the code in the 2013 Dev Guide&amp;nbsp;(&lt;A target="_blank" title="AutoCAD 2013 Developer's Guide: lock &amp;amp; unlock a document" href="http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-4E1AAFA9-740E-4097-800C-CAED09CDFF12.htm,topicNumber=d30e712496" rel="nofollow"&gt;here&lt;/A&gt;, search for "LockDoc") to compile as it has not been updated to use the new DocumentCollectionExtension methods. I have substituted the new method calls into that code but still have the activation problem."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this message as been plusblished 2 years ago but I just found the solution of the same problem&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use a "CommandFlags.Session" parameters when you declare your CommandMethod.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exemple:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;CommandMethod("ExportSHP", "EXPSHP", CommandFlags.Session + CommandFlags.UsePickSet)&amp;gt; _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub Export_Shape()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End sub&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For more informations see :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A target="_self" href="http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-F77E8FE0-8034-4704-93BD-F717608F8223"&gt;Command Definition (.NET)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A target="_self" href="http://adndevblog.typepad.com/autocad/2012/05/when-to-lock-the-document.html"&gt;http://adndevblog.typepad.com/autocad/2012/05/when-to-lock-the-document.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2015 10:29:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mdiactivedocument-and-documentactivated/m-p/5504573#M53184</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-02-12T10:29:23Z</dc:date>
    </item>
  </channel>
</rss>

