good day to you all
for my work im writing some apps, currently im working on something that needs to be activated when save is completed
right now i'm working on the trigger part
the're a few problems
- with several drawings open the the dll loaded, the save all command kills the handlers
- when you have several drawings open, when loading the dll, it applies the save handler tot the first drawing
- when a drawing was open with the handlers when autocad crashes, it keeps crashing autocad
anyone has any suggestions?
thanks in advance, and merry christmas
Björn
here's the code
Imports System Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.EditorInput Imports System.IO <Assembly: ExtensionApplication(GetType(pdfsaver.MyPlugin))> Namespace pdfsaver Public Class MyPlugin Implements IExtensionApplication Private BS_DocMan As DocumentCollection Private Shared BS_Controllers As Dictionary(Of Document, PerDocController) Public Sub Initialize() Implements IExtensionApplication.Initialize '#### document controller #### BS_DocMan = Application.DocumentManager BS_Controllers = New Dictionary(Of Document, PerDocController) If Not (BS_Controllers.ContainsKey(e.Document)) Then For Each BS_document As Document In BS_DocMan BS_Controllers.Add(BS_document, New PerDocController(BS_document)) Next AddHandler BS_DocMan.DocumentActivated, AddressOf DocumentActivated AddHandler BS_DocMan.DocumentCreated, AddressOf DocumentCreated AddHandler BS_DocMan.DocumentToBeDestroyed, AddressOf DocumentToBeDestroyed end if MsgBox("handlers added") End Sub Public Sub Terminate() Implements IExtensionApplication.Terminate MsgBox("handlers will be removed") RemoveHandler BS_DocMan.DocumentActivated, AddressOf DocumentActivated RemoveHandler BS_DocMan.DocumentCreated, AddressOf DocumentCreated RemoveHandler BS_DocMan.DocumentToBeDestroyed, AddressOf DocumentToBeDestroyed MsgBox("handlers removed") End Sub Private Sub DocumentActivated(sender As Object, e As DocumentCollectionEventArgs) If Not (BS_Controllers.ContainsKey(e.Document)) Then BS_Controllers.Add(e.Document, New PerDocController(e.Document)) e.Document.Editor.WriteMessage(vbCrLf + " - Document Activated! ") End If e.Document.Editor.WriteMessage(vbCrLf + " - Document Activated! 2") End Sub Private Sub DocumentToBeDestroyed(sender As Object, e As DocumentCollectionEventArgs) If (BS_Controllers.ContainsKey(e.Document)) Then BS_Controllers(e.Document).Destroy() BS_Controllers.Remove(e.Document) End If e.Document.Editor.WriteMessage(vbCrLf + " - DocumentToBeDestroyed ") End Sub Private Sub DocumentCreated(sender As Object, e As DocumentCollectionEventArgs) If Not (BS_Controllers.ContainsKey(e.Document)) Then BS_Controllers.Add(e.Document, New PerDocController(e.Document)) e.Document.Editor.WriteMessage(vbCrLf + " - Document Created! ") End If e.Document.Editor.WriteMessage(vbCrLf + " - Document Created! 2") End Sub End Class Public Class PerDocController Private BS_document As Document Public Sub New(ByVal document As Document) BS_document = document ' AddHandler BS_document.Database.BeginSave, AddressOf BeginSave AddHandler BS_document.Database.SaveComplete, AddressOf SaveComplete BS_document.Editor.WriteMessage(vbCrLf + " - Savehandler Added! ") End Sub Public Sub Destroy() ' RemoveHandler BS_document.Database.BeginSave, AddressOf BeginSave RemoveHandler BS_document.Database.SaveComplete, AddressOf SaveComplete MsgBox("destroy activated") End Sub Private Sub SaveComplete(sender As Object, e As DatabaseIOEventArgs) BS_document.Editor.WriteMessage(vbCrLf + " - Save Complete! ") End Sub End Class End Namespace
DocumentActivated is called each time you switch from a document to another, so it's not here that you need to setup your SaveComplete event handler. Just use DocumentCreated and DocumentToBeDestroyed. For the blank document AutoCAD opens at startup, you should use DocumentBecameCurrent.
Can't find what you're looking for? Ask the community or share your knowledge.