DocumentCollection object events are used to respond to the open documents in the application. DocumentCollection events, unlike Document object events, remain registered until AutoCAD is shutdown or until they are unregistered.
The following events are available for DocumentCollection objects:
Triggered when a document window is activated.
Triggered after the active document window is deactivated or destroyed.
Triggered when a document window is set current and is different from the previous active document window.
Triggered after a document window is created. Occurs after a new drawing is created or an existing drawing is opened.
Triggered just before a document window is created. Occurs before a new drawing is created or an existing drawing is opened.
Triggered when a request to create a new drawing or to open an existing drawing is cancelled.
Triggered before a document window is destroyed and its associated database object is deleted.
Triggered after the lock mode of a document has changed.
Triggered after the lock mode change is vetoed.
Triggered before the lock mode of a document is changed.
Triggered when a document is about to be activated.
Triggered when a document is about to be deactivated.
Triggered when a document is about to be destroyed.
The following example uses the DocumentActivated event to indicate when a drawing window has been activated. A message box with the name of the drawing that is activated is displayed when the event occurs.
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices <CommandMethod("AddDocColEvent")> _ Public Sub AddDocColEvent() AddHandler Application.DocumentManager.DocumentActivated, _ AddressOf docColDocAct End Sub <CommandMethod("RemoveDocColEvent")> _ Public Sub RemoveDocColEvent() RemoveHandler Application.DocumentManager.DocumentActivated, _ AddressOf docColDocAct End Sub Public Sub docColDocAct(ByVal senderObj As Object, _ ByVal docColDocActEvtArgs As DocumentCollectionEventArgs) Application.ShowAlertDialog(docColDocActEvtArgs.Document.Name & _ " was activated.") End Sub
using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; [CommandMethod("AddDocColEvent")] public void AddDocColEvent() { Application.DocumentManager.DocumentActivated += new DocumentCollectionEventHandler(docColDocAct); } [CommandMethod("RemoveDocColEvent")] public void RemoveDocColEvent() { Application.DocumentManager.DocumentActivated -= new DocumentCollectionEventHandler(docColDocAct); } public void docColDocAct(object senderObj, DocumentCollectionEventArgs docColDocActEvtArgs) { Application.ShowAlertDialog(docColDocActEvtArgs.Document.Name + " was activated."); }
Private Sub AcadDocument_Activate() ' This example intercepts the Document Activate event. MsgBox ThisDrawing.Name & " was activated." End Sub