SAVEAS

#1
I have small working code.
How can I change it to saveas NewLongFilNam?
Sometime MdiActiveDocument is DXF and I want it save as DWG.

Code: Select all

       //---------------------------------------------------------------------------------
       internal static bool SaveAndCloseDrawingTest(Document acDocMain, string NewLongFilNam)
       {
           Document acDoc = Application.DocumentManager.MdiActiveDocument;
           Database acDb = acDoc.Database;
           try
           {
               acDoc.SendStringToExecute("_QSAVE", true, true, false);
               acDoc.SendStringToExecute("_CLOSE", true, true, false);
               acDb.SaveAs(NewLongFilNam, true, DwgVersion.Current, acDoc.Database.SecurityParameters);  // Do not work
               //Application.DocumentManager.MdiActiveDocument = acDocMain;
           }
           catch (Exception Ex)
           {
               acDoc.Editor.WriteMessage(Ex.ToString());
               return false;
           }
           return true;
       }
       //---------------------------------------------------------------------------------

Re: SAVEAS

#2
Hi Raho,
This saves the current file (both CAD file and dxf file, ...) to a new name and closes the file.

Code: Select all

        [CommandMethod("SaveToCad")]
        public static void SaveAsAndCloseDrawing()
        {
            Document acDoc = IntelliCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            string fileName = acDoc.Name;
            if (!File.Exists(fileName))
                return;

            string NewFileName = Path.Combine(Path.GetDirectoryName(fileName),
                Path.GetFileNameWithoutExtension(fileName) + "_new.dwg");
            
            try
            {
                Database acDb = acDoc.Database;
                using (acDoc.LockDocument())
                {
                    acDb.SaveAs(NewFileName, true, DwgVersion.AC1032, acDb.SecurityParameters);
                }

                acDoc.CloseAndDiscard();
            }
            catch (Teigha.Runtime.Exception Ex)
            {
                acDoc.Editor.WriteMessage(Ex.ToString());
            }
        }
cron