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:
Enable a DocumentCollection object event
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.");
}