Watch Save\SaveAs Event?

Watch Save\SaveAs Event?

Anonymous
Not applicable
4,074 Views
7 Replies
Message 1 of 8

Watch Save\SaveAs Event?

Anonymous
Not applicable
I am fairly new to vb.net programming so sorry if this is an elementary question. I checked some post but didn't see what I was looking for.

I want to know how to watch for a save or saveas event. Basically I want to start a command after a save or saveas commands are finished. BTW, I'm coding this in vb.net.

Thanks,

Dan
0 Likes
4,075 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Hi.
I will give you a code sample in C#.
You have to handle the DocumentLockModeChanged event like this:

Application.DocumentManager.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(callback_DocumentManager_DocumentLockModeChanged);


and then check if the command is SAVE or SAVEAS:

private static void callback_DocumentManager_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
{
if (e.GlobalCommandName == "QSAVE" || e.GlobalCommandName == "SAVE"
|| e.GlobalCommandName == "SAVEAS")
{
// do you code
}

}

the end of the command will be like #SAVE #SAVEAS.

Edited by: maxim_voloshin on Jun 24, 2009 6:59 PM Edited by: maxim_voloshin on Jun 24, 2009 7:00 PM
0 Likes
Message 3 of 8

Anonymous
Not applicable
Thanks for the code. I was able to write this in vb.net but it doesn't seem to watch the Save\SaveAs\QSave event. During the debug it doesn't even get into the code.

here's what i have so far. I'm a noobie so bare with me. Thanks!

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

Public Class Class1

Private Sub Sub_Handler()
Try
AddHandler Application.DocumentManager.DocumentLockModeChanged, New DocumentLockModeChangedEventHandler(AddressOf docChange)
Catch ex As Exception

End Try
End Sub

Public Sub docChange(ByVal sender As Object, ByVal e As DocumentLockModeChangedEventArgs)
If e.GlobalCommandName = "_QSAVE" Or e.GlobalCommandName = "_SAVE" Or e.GlobalCommandName = "_SAVEAS" Then
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage("Save has occured")
End If
End Sub
0 Likes
Message 4 of 8

Anonymous
Not applicable
Well after playing around here's what I got. It will watch the save events. I placed a message box to show me if the watch worked but it seems to be displaying twice. Maybe at the beginning of the command and at the end. I want just the end so that my next task will run after the save is completed. Any feedback will be greatly appreciated. TIA.

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

Public Class Class1
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

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

End Try
End Sub

Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
RemoveHandler Application.DocumentManager.DocumentLockModeChanged, subHandler
End Sub
End Class
0 Likes
Message 5 of 8

Anonymous
Not applicable
Try

If e.GlobalCommandName = "#QSAVE" Or e.GlobalCommandName = "#SAVE" Or e.GlobalCommandName = "#SAVEAS" Then
Application.ShowAlertDialog("Save has occurred")
End If
0 Likes
Message 6 of 8

Anonymous
Not applicable
Sorry that didn't work. I still get two dialog boxes. Any other suggestions.

Thanks for the reply!
0 Likes
Message 7 of 8

cadMeUp
Collaborator
Collaborator
Check out the attached file for monitoring Database 'save' events. Just displays an alert dialog when Database.BeginSave & Database.SaveComplete are called. The sample code file is for AutoCAD 2009 VB.
Message 8 of 8

Anonymous
Not applicable
Thanks! I will give that a try.
0 Likes