Event Monitor

Event Monitor

dbrblg
Collaborator Collaborator
1,035 Views
4 Replies
Message 1 of 5

Event Monitor

dbrblg
Collaborator
Collaborator

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

0 Likes
1,036 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

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

0 Likes
Message 3 of 5

dbrblg
Collaborator
Collaborator

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

0 Likes
Message 4 of 5

Anonymous
Not applicable

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

    }
}

 

 

0 Likes
Message 5 of 5

jeff
Collaborator
Collaborator

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
0 Likes