I need the ability for my VB.NET application to save down to 2010 format when I am running 2015 autocad
Thanks!
I tried this, but the problem is that I get an unhandled access violation when I try to save the current drawing down to 2010 format. I don't want to rename it to something else, and I cannot force my users to exit the drawing when saving. Is there some way to get around this?
Thanks
Is there no solution to this? I just want AutoCAD 2015 to always save down to 2010 format because I have some users using machines with 2015, and other users using 2010, and they will all be accessing the same files.
Thanks
i think that now you are supposed to use SaveAs method, you can check the backward compability (if you have the ARX downloaded and look for dbmain.h, for acdbSaveAs2000(), etc) those can be p-invoked, i tried that many moons ago, but no luck backthen... maybe (not tested, just grabbed from my old dwgConvert class), something like, in my case was a conversion from ADT to AutoCAD, see if you use the built-in +SAVEAS command, might work, do not recall if now it is a command line access and no need to do any Pinvoke:
const int RTNORM = 5100; const int RTCAN = -5002; const short RTSTR = 5005; const string PrefixConvert = "CONVERTED-"; const string prefixAcad = "ACAD-"; const string prefixBackup = "BACKUP-"; [SuppressUnmanagedCodeSecurity] [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)] extern static int acedCmd(IntPtr resbuf); public void MySaveAsTest() { // save the drawing to a new one using exporttoautocad // I need to use this approach - any other I tried did not work // like SaveAs() or SaveDatabaseAs2000() var resultBuffer = new ResultBuffer { new TypedValue(RTSTR, "_.-EXPORTTOAUTOCAD"), new TypedValue(RTSTR, "_Format"), new TypedValue(RTSTR, "2000"), new TypedValue(RTSTR, "_Type"), new TypedValue(RTSTR, "_Insert"), new TypedValue(RTSTR, "_Prefix"), new TypedValue(RTSTR, PrefixConvert), new TypedValue(RTSTR, ""), new TypedValue(RTSTR, "") }; var status = acedCmd(resultBuffer.UnmanagedObject); if (status == RTNORM || status == RTCAN) { //... } }
hth.-
Here is the code that generated the exception error:
acCurdb.SaveAs(acdoc.Name, DwgVersion.AC1024)
this works for me, see if helps now:
[CommandMethod("MYSAVEAS")] public void cmd_mySaveAs() { var document = AcadApp.DocumentManager.MdiActiveDocument; var database = document.Database; document.DowngradeDocOpen(false); document.PushDbmod(); database.SaveAs(database.Filename, DwgVersion.AC1024); document.PopDbmod(); }
@LE3 DowngradeDocOpen throws an exception (eInvalidContext) if called with bPromptForSave at false and a modified drawing. And you need to call UpgradeDocOpen otherwise the drawing will stay in read-only mode.
When you save the active drawing, you must use the overload which take a boolean value for bBakAndRename and pass true for this argument:
[CommandMethod("MYSAVEAS")] public void MySaveAs() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; if (doc.IsNamedDrawing) { db.SaveAs(doc.Name, bBakAndRename: true, version: DwgVersion.AC1024, security: db.SecurityParameters); } else { // Prompt for file name... } }
You've got a FileSharingViolation because AutoCAD maintains a lock on the file. When you pass true for bBakAndRename, AutoCAD release the lock, rename the active drawing with a bak extension and if it success, it writes the new .dwg file. If something goes wrong during the write, the .bak file is safe.
Don't use db.Filename (use doc.Name instead) as it will contain the path of the template (.dwt) used to create the drawing. And check if the drawing has already a name with IsNamedDrawing.