Save down to version 2010 from 2015 in VB.NET

Save down to version 2010 from 2015 in VB.NET

Anonymous
Not applicable
1,234 Views
12 Replies
Message 1 of 13

Save down to version 2010 from 2015 in VB.NET

Anonymous
Not applicable

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

 

Thanks!

0 Likes
1,235 Views
12 Replies
Replies (12)
Message 2 of 13

Keith.Brown
Advisor
Advisor

look at database.SaveAs(fileName, DwgVersion)

0 Likes
Message 3 of 13

Anonymous
Not applicable

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

 

0 Likes
Message 4 of 13

Anonymous
Not applicable

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

 

0 Likes
Message 5 of 13

Anonymous
Not applicable

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

 

 

0 Likes
Message 6 of 13

fieldguy
Advisor
Advisor

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

0 Likes
Message 7 of 13

Anonymous
Not applicable

Here is the code that generated the exception error:

 

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

 

0 Likes
Message 8 of 13

fieldguy
Advisor
Advisor

What about the security parameters?

0 Likes
Message 9 of 13

Anonymous
Not applicable

That is all I used for the code.

0 Likes
Message 10 of 13

Anonymous
Not applicable

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

@Anonymous 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
0 Likes
Message 12 of 13

FRFR1426
Collaborator
Collaborator

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

Anonymous
Not applicable

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

0 Likes