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

Trigger Autosave

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
wbdehaan
857 Views, 5 Replies

Trigger Autosave

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

5 REPLIES 5
Message 2 of 6
_gile
in reply to: wbdehaan

Hi,

 

what about using SaveAs() with a suffixed filename?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6
wbdehaan
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

Message 4 of 6
Matti72
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.

Message 5 of 6
wbdehaan
in reply to: wbdehaan

It works, thank you very much!

 

Wouter

Message 6 of 6
ehrman
in reply to: wbdehaan

It's been a long time since this was originally posted, but I also needed to trigger an autosave.  building on the previous code, I came up with this.  It appears to work almost exactly like the AutoCAD internal autosave (no guarantees)

 

Public Sub TriggerAutosave()

   Dim DB As Database = Application.DocumentManager.MdiActiveDocument.Database

   Dim SavePath As String = Application.GetSystemVariable("SAVEFILEPATH")

   Dim SaveName As String = Application.GetSystemVariable("SAVEFILE")

   Dim FullName As String = SavePath & SaveName

   If SaveName = "" Then

      Dim SaveName1 As String = Application.GetSystemVariable("DWGNAME")

      SaveName1 = Replace(SaveName1, ".dwg", "*.sv$")

            SaveName = Dir(SavePath & SaveName1)

      If SaveName <> "" Then

         FullName = SavePath & SaveName

      Else

         FullName = SavePath & Replace(SaveName1, "*", "_1_1_0001")

      End If

   End If

   DB.SaveAs(FullName, DwgVersion.Current)

End Sub

Bob

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