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

Save down to version 2010 from 2015 in VB.NET

12 REPLIES 12
Reply
Message 1 of 13
jeffjolliffe
746 Views, 12 Replies

Save down to version 2010 from 2015 in VB.NET

I need the ability for my VB.NET application to save down to 2010 format when I am running 2015 autocad 

 

Thanks!

12 REPLIES 12
Message 2 of 13
Keith.Brown
in reply to: jeffjolliffe

look at database.SaveAs(fileName, DwgVersion)

Message 3 of 13
jeffjolliffe
in reply to: Keith.Brown

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

 

Message 4 of 13
jeffjolliffe
in reply to: jeffjolliffe

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

 

Message 5 of 13
LE3
Advocate
in reply to: jeffjolliffe

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.-

 

 

Message 6 of 13
fieldguy
in reply to: jeffjolliffe

Can you show the code that generates the exception?  SaveAs is described >>here<<

Message 7 of 13
jeffjolliffe
in reply to: fieldguy

Here is the code that generated the exception error:

 

acCurdb.SaveAs(acdoc.Name, DwgVersion.AC1024)

 

Message 8 of 13
fieldguy
in reply to: jeffjolliffe

What about the security parameters?

Message 9 of 13
jeffjolliffe
in reply to: fieldguy

That is all I used for the code.

Message 10 of 13
LE3
Advocate
in reply to: jeffjolliffe

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();
        }
Message 11 of 13
FRFR1426
in reply to: LE3

@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.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 12 of 13
FRFR1426
in reply to: FRFR1426

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.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 13 of 13
LE3
Advocate
in reply to: FRFR1426

yes, i did not went in deep with my tests, the usage of SaveAs in your post is the ticket - thanks!

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