.NET

Reply
Valued Contributor
wbdehaan
Posts: 64
Registered: ‎11-01-2001
Message 1 of 5 (240 Views)
Accepted Solution

Trigger Autosave

240 Views, 4 Replies
09-27-2013 02:34 AM

Hi, 

 

is it possible to trigger an Autosave before executing my vb.net-code? I'm rather new to vb.netcode and in case of an unexpexted error AutoCad sometimes crashes. If I Could trigger an auto-save before the code is run, no information in the drawing is lost, but can be obtained in an autosave-file.

 

I cannot trigger a Save of SaveAs, because i don't know if the user wanted to save the drawing, for examples if the user reads an older drawing, removes/deletes objects etc, but is unaware of the drawing being saved, it could result in problems.

 

kind regards Wouter

If you use the SaveAs of the Database ( and not of the document), then the Database is saved without changing the name of the drawing. So the drawing will still be saved under it's old name, if the user pushes the save button.

 

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
string f1 = doc.Name;
string f2 = db.Filename; // should be the same then f1
db.SaveAs("D:\\Test.dwg", DwgVersion.Current);
//now:
// doc.Name is still f1
// but db.Filename is "D:\\Test.dwg"

 A save Command from the user will use the doc.Name, not the filename of the db.

*Expert Elite*
_gile
Posts: 2,106
Registered: ‎04-29-2006
Message 2 of 5 (228 Views)

Re : Trigger Autosave

09-27-2013 03:20 AM in reply to: wbdehaan

Hi,

 

what about using SaveAs() with a suffixed filename?

Gilles Chanteau
Valued Contributor
wbdehaan
Posts: 64
Registered: ‎11-01-2001
Message 3 of 5 (221 Views)

Re: Trigger Autosave

09-27-2013 04:00 AM in reply to: wbdehaan

Thanks for you reply,

 

if I use saveas with a prefix, the active drawing is saved in that location, if the user will save afterwards, thinking that it is saved in the original location, it will actually be saved in de new autosave-directory, which is not an option.

 

If it is possible to do a save-as with a prefix, and then reset the drawing-name and path to the original drawing & location, it is a solution, but I don't know how to do that, 

 

regards,

 

Wouter

Contributor
Matti72
Posts: 25
Registered: ‎09-28-2004
Message 4 of 5 (206 Views)

Re: Trigger Autosave

09-27-2013 05:27 AM in reply to: wbdehaan

If you use the SaveAs of the Database ( and not of the document), then the Database is saved without changing the name of the drawing. So the drawing will still be saved under it's old name, if the user pushes the save button.

 

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;

string f1 = doc.Name;    
string f2 = db.Filename; // should be the same then f1
			
db.SaveAs("D:\\Test.dwg", DwgVersion.Current);

//now:
// doc.Name is still f1
// but db.Filename is "D:\\Test.dwg"

 A save Command from the user will use the doc.Name, not the filename of the db.

Valued Contributor
wbdehaan
Posts: 64
Registered: ‎11-01-2001
Message 5 of 5 (187 Views)

Re: Trigger Autosave

09-27-2013 07:18 AM in reply to: wbdehaan

It works, thank you very much!

 

Wouter

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.