0

EndSave (AutoCAD) is member of what (.net vb)?

Is it Application.DocumentManager.MdiActiveDocument?

I don't know where it is, so I can add a handler to register its event.

Grant Miller
  • 27,532
  • 16
  • 147
  • 165
Rita Aguiar
  • 65
  • 1
  • 10
  • it doesn't exist so you have to add your own handling. – Simo Sep 10 '18 at 13:39
  • I [Googled "EndSave AutoCAD"](https://www.google.com/search?q=EndSave+AutoCAD) and [How to handle the EndSave event (.net vb)?](https://forums.autodesk.com/t5/autocad-forum/how-to-handle-the-endsave-event-net-vb/td-p/8252214) was one of the first results. It would be helpful to potential respondents if your StackOverflow question contained as much detail and description as your AutoDesk forums question since the title, if not the body, takes a few reads to figure out what you're asking here. – Lance U. Matthews Sep 10 '18 at 23:50

2 Answers2

1

First you have to delcare the imports:

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports System.Windows

1) handle he DocumentLockModeChanged event like this:

Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
    Try
        subHandler = New DocumentLockModeChangedEventHandler(AddressOf docChange)
        AddHandler Application.DocumentManager.DocumentLockModeChanged, subHandler
    Catch ex As Exception
        Err.Clear()
    End Try
End Sub

2) and then check if the command is SAVE or SAVEAS:

Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Dim subHandler As [Delegate]
Public Sub docChange(ByVal sender As Object, ByVal e As DocumentLockModeChangedEventArgs)
    If e.GlobalCommandName = "QSAVE" Or e.GlobalCommandName = "SAVE" Or e.GlobalCommandName = "SAVEAS" Then   
        Application.ShowAlertDialog("Save has occurred")
    End If
End Sub

At this point if you want, you can add the handle for the terminate event, like this:

Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
    RemoveHandler Application.DocumentManager.DocumentLockModeChanged, subHandler
End Sub
Simo
  • 955
  • 8
  • 18
  • Thank you. I've seen that page already. That is for the DocumentDestroyed Event. I'm looking for the EndSave Event. I don't know what is the delegate for the EndSave Event. What is it? – Rita Aguiar Sep 10 '18 at 12:07
  • I found the answer but currently I'm having lunch, give me a few minutes ;) – Simo Sep 10 '18 at 12:20
  • Hi @Simo. I have insert it inside a class. Now it says: Interface 'IExtensionApplication' is not implemented by this class What does this mean? And then subHandler and docChange are not declared. – Rita Aguiar Sep 10 '18 at 14:44
  • @RitaAguiar sorry but StackOverflow is not a place where someone else codes programs for you. Is a place where someone helps you. Now is up to you to read the documentation about AutoCad, in a more specific way the documentation related to `IExtensionApplication`. This is another [example](https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2017/ENU/AutoCAD-NET/files/GUID-FA3B4125-F7BD-4E89-969F-9DCC90AC6977-htm.html) of how to implements `IExtensionApplication` – Simo Sep 10 '18 at 14:52
  • I managed to implement this, however it will register when the user executes the save commands and before he finishes them. If the user cancels the save, it has already register as if he did save the drawing. – Rita Aguiar Sep 11 '18 at 08:38
  • I dediced to use the CommandEnded Event instead of the DocumentLockModeChanged Now it only register if the save commands have been ended. – Rita Aguiar Sep 11 '18 at 08:45
  • 1
    Yes, this is the issue, but is the best option possible – Simo Sep 11 '18 at 08:46
  • 1
    @RitaAguiar edit your post to add your solution, or add an answer – Simo Sep 11 '18 at 09:05
1

I dediced to use the CommandEnded Event instead of the DocumentLockModeChanged. Now it only register if the save commands (QSAVe, SAVE, SAVEAS) have been ended.

Rita Aguiar
  • 65
  • 1
  • 10