Message 1 of 8
Document collection events
Not applicable
07-06-2008
08:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everyone,
Recently I have been do some work with the document collection events. Specifically, I have been trying to measure time in drawings for costing purposes. To this end I want to catch the DocumentBecameCurrent event to begin timing and also another event to stop timing when a docment stops being current.
What I noticed in my coding is that the event triggers multiple times, this surpises me and makes it more complicated to do what I want to do.
The code below is just a skeleton to demonstrate what happens. If you run it with 2 or more drawings, the event will fire three times, once with the current drawing and then twice with the new(current drawing) when you change drawings (ie CTL+TAB).
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application
< extensionapplication="">
Public Class CWCHClass
Implements IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
AddHandler AcadApp.DocumentManager.DocumentBecameCurrent, AddressOf OnDocumentBecameCurrent
End Sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
End Sub
Private Sub OnDocumentBecameCurrent(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
Debug.Print(e.Document.Name)
Msg("TEST: Document Became Current: " & e.Document.Name)
End Sub
Public Sub Msg(ByVal Text As String)
Dim Ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor()
Ed.WriteMessage(vbCrLf & Text)
End Sub
End Class
My questions to the group are:
1. Is the multiple triggering normal behaviour with the DocumentBecameCurrent event? And if so are there strategies to deal with it?
2. What is the best event to monitor, so that I can catch when a document ceases to be current (ie DocumentToBeDeactivated or DocumentActivationChanged)
Regards
Martin Duke>
Recently I have been do some work with the document collection events. Specifically, I have been trying to measure time in drawings for costing purposes. To this end I want to catch the DocumentBecameCurrent event to begin timing and also another event to stop timing when a docment stops being current.
What I noticed in my coding is that the event triggers multiple times, this surpises me and makes it more complicated to do what I want to do.
The code below is just a skeleton to demonstrate what happens. If you run it with 2 or more drawings, the event will fire three times, once with the current drawing and then twice with the new(current drawing) when you change drawings (ie CTL+TAB).
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application
< extensionapplication="">
Public Class CWCHClass
Implements IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
AddHandler AcadApp.DocumentManager.DocumentBecameCurrent, AddressOf OnDocumentBecameCurrent
End Sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
End Sub
Private Sub OnDocumentBecameCurrent(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
Debug.Print(e.Document.Name)
Msg("TEST: Document Became Current: " & e.Document.Name)
End Sub
Public Sub Msg(ByVal Text As String)
Dim Ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor()
Ed.WriteMessage(vbCrLf & Text)
End Sub
End Class
My questions to the group are:
1. Is the multiple triggering normal behaviour with the DocumentBecameCurrent event? And if so are there strategies to deal with it?
2. What is the best event to monitor, so that I can catch when a document ceases to be current (ie DocumentToBeDeactivated or DocumentActivationChanged)
Regards
Martin Duke>