.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Event Handler For Automatic Drawing Backup (before BAK file is created)

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
kbrown
572 Views, 8 Replies

Event Handler For Automatic Drawing Backup (before BAK file is created)

My plugin embeds data in the NOD. To do this, I handle the Database.BeginSave event. Each time my handler is invoked, I write out the most recent data to the NOD.

 

This works well, except when AutoCAD crashes and the user restores from a BAK file. The drawing data, inclucing geometry, is restored. But the data in the NOD entries I use to store my application data is the data from the last Save, because BeginSave never fires.

 

Is there an event I can subscribe to, similar to Database.BeginSave, which fires before a BAK file is created?

 

Thanks,

Kevin

8 REPLIES 8
Message 2 of 9
norman.yuan
in reply to: kbrown

Ity looks like your issue is thta the data you aved in NOD is always a "saving" behind in the .BAK version than in .DWG version, because when Database.BeginSave fires, the .BAK has already being created.

 

You may want to try to handle Document.CommandWilLStart event, and test the command name in the eventhandler's argument for "SAVE", "QSAVE" and/or "SAVEAS". If the command is one of them, you save data into NOD. In case you want to reverse the saving in NOD when the command is cancelled, you may also handle CommandCancelled event to remove latest saving in NOD. 

 

I believe CommandWillStart/Cancelled fires before .BAK is created, but I have not tested myself.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 9
kbrown
in reply to: norman.yuan

Am I correct that when restore options for a drawing are displayed after an AutoCAD crash, the BAK file is used to restore the drawing to a state after the last Save but before the crash? Maybe I confused the question by asking about BAK files. If the BAK file is created as part of a normal Save routine (i.e. drawing is saved to BAK file. If Save succeeds, BAK file replaces DWG file), then I am looking for some other automatic saving which occurs and allows for restoring lost data after a crash. Sorry for the confusion.

 

Thanks,

Kevin

Message 4 of 9
kbrown
in reply to: norman.yuan

I was indeed mistaken. I am looking for an event that fires when an AutoSave occurs (just before an auto save, actually). Sorry about the confusion.

 

Thanks,

Kevin

Message 5 of 9
norman.yuan
in reply to: kbrown

If you were looking at Autosave, then your orignal question would not make much sense: autosaving does not create .BAK file when it executes.

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 9
kbrown
in reply to: norman.yuan

As I said, I thought auto save produced the BAK files (an associate indicated this was the case and I ****umed he was correct).

 

Knowing what to search for lead to this post: http://adndevblog.typepad.com/autocad/2012/08/about-autosave-and-notificationsevents.html

 

In the comments a user mentions using the event DocumentManager.DocumentLockModeChanged to detect when AUTO_SAVE commands are about to be executed:

 

"Sorry for dredging up older post's. We have tapped into the DocumentManager.DocumentLockModeChanged event to see various things and prevent commands from running during certain times in our application.

The DocumentLockModeChangedEventArgs parameter has a .GlobalCommandName property that shows us when "AUTO_SAVE" is being called during one of our routines. This is easy to prevent as there is also a Veto() function to cancel the "AUTO_SAVE"."

 

I was able to accomplish what I needed to using this event and checking if GlobalCommandName = "AUTO_SAVE", or at least initial testing has been successful. Sorry for the confusing post and thank you for trying to help.

Message 7 of 9
kbrown
in reply to: norman.yuan

Do you believe using the Document.CommandWillStart event as you suggested (only looking for the command AUTO_SAVE) is a better approach than DocumentManager.DocumentLockModeChanged as described previously for my particular need?

 

Thanks,

Kevin

Message 8 of 9
norman.yuan
in reply to: kbrown

Based on my test, CommandWillStart is not triggered by autosaving.

Norman Yuan

Drive CAD With Code

EESignature

Message 9 of 9
kbrown
in reply to: norman.yuan

Thanks again for you help.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost