.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Event Monitor

4 REPLIES 4
Reply
Message 1 of 5
dbrblg
717 Views, 4 Replies

Event Monitor

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

4 REPLIES 4
Message 2 of 5
bjhuffine
in reply to: dbrblg

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

Message 3 of 5
dbrblg
in reply to: bjhuffine

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

Message 4 of 5
bjhuffine
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

    }
}

 

 

Message 5 of 5
jeff
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost