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
Solved! Go to Solution.
Solved by Matti72. Go to Solution.
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
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.
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
Can't find what you're looking for? Ask the community or share your knowledge.