.NET

Reply
Distinguished Contributor
dbrblg
Posts: 314
Registered: ‎10-10-2007
Message 1 of 5 (322 Views)

Event Monitor

322 Views, 4 Replies
09-07-2012 03:28 AM

Bit of a long shot here, but does anyone know of an application or piece of code which monitors AutoCAD and reports when events are triggered?

 

I'm looking to see when events are triggered in relation to each other and wonder if anyone else has attempted anything like this in the past?

 

Many thanks

Valued Contributor
bjhuffine
Posts: 74
Registered: ‎08-13-2008
Message 2 of 5 (317 Views)

Re: Event Monitor

09-07-2012 04:45 AM in reply to: dbrblg

Are you talking about watching events internally to AutoCAD or externally from a systems' standpoint?

Distinguished Contributor
dbrblg
Posts: 314
Registered: ‎10-10-2007
Message 3 of 5 (312 Views)

Re: Event Monitor

09-07-2012 05:10 AM in reply to: bjhuffine

Watching events internally to AutoCAD, although if the latter existed i'd have that too :smileywink:

Valued Contributor
bjhuffine
Posts: 74
Registered: ‎08-13-2008
Message 4 of 5 (302 Views)

Re: Event Monitor

09-07-2012 06:28 AM in reply to: dbrblg

Cool... I just didn't want to mention anything that doesn't apply.  You can find some things on it here: http://adndevblog.typepad.com/autocad/ 

 

After doing a search I found these specifically:

http://adndevblog.typepad.com/autocad/2012/08/managing-events-at-a-per-document-level.html

http://adndevblog.typepad.com/autocad/2012/05/handling-events-in-vbnet.html

(there was more so who knows there may be something more specific to what you're looking for.  Also, I didn't look at these in any great detail so hopefully their accurate).

 

Here's something I did some time back in a project where I needed to track a few application-level events... specifically window moved and sized events as well as determining whether or not AutoCAD is quiescent before moving on to a specific process.  I've modified it so that you can use it to illustrate in your own project (no command is necessary... just netload and try a few things out in AutoCAD).

 

 

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Internal.Reactors;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;

[assembly: ExtensionApplication(typeof(AutoCADEvents.CADApplicationExtension))]

namespace AutoCADEvents
{

    public sealed class CADApplicationExtension : IExtensionApplication
    {

        #region IExtensionApplication Interface Implementation To Register/Deregister Events

        void IExtensionApplication.Initialize()
        {
            ApplicationEventManager appEventMgr = ApplicationEventManager.Instance();
            appEventMgr.ApplicationMainWindowMoved += new ApplicationMainWindowMovedEventHandler(appEventMgr_ApplicationMainWindowMoved);
            appEventMgr.ApplicationMainWindowSized += new ApplicationMainWindowSizedEventHandler(appEventMgr_ApplicationMainWindowSized);


            Application.DocumentManager.DocumentBecameCurrent += new DocumentCollectionEventHandler(DocumentManager_DocumentBecameCurrent);
            Application.DocumentManager.DocumentToBeDeactivated += new DocumentCollectionEventHandler(DocumentManager_DocumentToBeDeactivated);
            Application.DocumentManager.DocumentToBeDestroyed += new DocumentCollectionEventHandler(DocumentManager_DocumentToBeDestroyed);
            Application.DocumentManager.DocumentDestroyed += new DocumentDestroyedEventHandler(DocumentManager_DocumentDestroyed);

            Document activeDoc = Application.DocumentManager.MdiActiveDocument;
            activeDoc.Editor.EnteringQuiescentState += new EventHandler(ed_EnteringQuiescentState);
            activeDoc.Editor.LeavingQuiescentState += new EventHandler(ed_LeavingQuiescentState);
            activeDoc.CommandCancelled += new CommandEventHandler(Document_CommandCancelled);
        }


        void IExtensionApplication.Terminate()
        {
            Application.DocumentManager.DocumentBecameCurrent -= new DocumentCollectionEventHandler(DocumentManager_DocumentBecameCurrent);
            Application.DocumentManager.DocumentToBeDeactivated -= new DocumentCollectionEventHandler(DocumentManager_DocumentToBeDeactivated);
            Application.DocumentManager.DocumentToBeDestroyed -= new DocumentCollectionEventHandler(DocumentManager_DocumentToBeDestroyed);
            Application.DocumentManager.DocumentDestroyed -= new DocumentDestroyedEventHandler(DocumentManager_DocumentDestroyed);

        }

        #endregion

        #region A Couple Window Events


        void appEventMgr_ApplicationMainWindowSized(object sender, EventArgs e)
        {
            try
            {
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                ed.WriteMessage("\nAutoCAD's window size just changed.\n");
            }
            catch { }
        }

        void appEventMgr_ApplicationMainWindowMoved(object sender, EventArgs e)
        {
            try
            {
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                ed.WriteMessage("\nAutoCAD's window was just moved.\n");
            }
            catch { }
        }

        #endregion

        #region Some Document Events Used to Determine Application Quiescence In This Example

        void DocumentManager_DocumentBecameCurrent(object sender, DocumentCollectionEventArgs e)
        {
            Editor ed = e.Document.Editor;
            ed.EnteringQuiescentState += new EventHandler(ed_EnteringQuiescentState);
            ed.LeavingQuiescentState += new EventHandler(ed_LeavingQuiescentState);
            e.Document.CommandCancelled += new CommandEventHandler(Document_CommandCancelled);
        }

        void DocumentManager_DocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e)
        {
            Editor ed = e.Document.Editor;
            ed.EnteringQuiescentState -= new EventHandler(ed_EnteringQuiescentState);
            ed.LeavingQuiescentState -= new EventHandler(ed_LeavingQuiescentState);
            e.Document.CommandCancelled -= new CommandEventHandler(Document_CommandCancelled);
        }

        void DocumentManager_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)
        {
            Editor ed = e.Document.Editor;
            ed.EnteringQuiescentState -= new EventHandler(ed_EnteringQuiescentState);
            ed.LeavingQuiescentState -= new EventHandler(ed_LeavingQuiescentState);
            e.Document.CommandCancelled -= new CommandEventHandler(Document_CommandCancelled);

        }

        void DocumentManager_DocumentDestroyed(object sender, DocumentDestroyedEventArgs e)
        {
            //If in Zero-Document state, create new drawing to make active

        }



        #endregion

        #region Event Handlers

        public static void ed_EnteringQuiescentState(object sender, EventArgs e)
        {
            Editor ed = sender as Editor;
            ed.WriteMessage("\nEntering Quiescence");
        }

        void ed_LeavingQuiescentState(object sender, EventArgs e)
        {
            Editor ed = sender as Editor;
            ed.WriteMessage("\nLeaving Quiescence");
        }

        void Document_CommandCancelled(object sender, CommandEventArgs e)
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("\nA command was just cancelled.");
        }

        #endregion

    }
}

 

 

Valued Mentor
jeff
Posts: 328
Registered: ‎05-12-2009
Message 5 of 5 (291 Views)

Re: Event Monitor

09-07-2012 08:54 AM in reply to: bjhuffine

Mgddbg has functionality to print events and some details to command line if you have not looked at that.

You can also find your answers @ TheSwamp
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.