Author Topic: exportlayout  (Read 194 times)

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 8
exportlayout
« on: September 07, 2017, 09:30:02 pm »
when I export many layouts ,if the file's size is small, the code is ok,but when the file's size is larger(exceed 1Mb ) ,the code will crash.According to my study, I think the problem is open and close the document repeately. but I have to use this method, because export layout doesn't work on side database, how can I solved this problem?


Code - C#: [Select]
  1.  
  2. public static void ExportAllLayouts()
  3.        {
  4.            System.Windows.Forms.OpenFileDialog dia = new System.Windows.Forms.OpenFileDialog();
  5.            dia.Filter = "dwg Files (*.dwg)|*.dwg|All files (*.*)|*.*";
  6.            dia.Multiselect = true;
  7.            if (dia.ShowDialog() != DialogResult.OK) return;
  8.  
  9.            string fileName = dia.FileNames[0];
  10.            FileInfo fi = new FileInfo(fileName);
  11.            string othersDir = System.IO.Directory.GetParent(fi.DirectoryName)  + @"\Others";
  12.            if (!System.IO.Directory.Exists(othersDir)) System.IO.Directory.CreateDirectory(othersDir);
  13.  
  14.  
  15.            for (int i = 0; i < dia.FileNames.Length; i++)
  16.            {
  17.                string oldFileFullName = dia.FileNames[i];
  18.                string forOthersFileFullName = othersDir + "\\" + dia.SafeFileNames[i];
  19.                if (GetAllPaperSpaceLayouts(oldFileFullName).Count != 1)
  20.                {
  21.                    Arx.Prompts.Editor.WriteMessage(oldFileFullName + "has more than one layout!!!");
  22.                    continue;
  23.                }
  24.                ExportLayout(oldFileFullName, forOthersFileFullName);
  25.            }
  26.  
  27.        }
  28.  
  29. public static void ExportLayout(string oldFileName, string newFileName)
  30.        {
  31.  
  32. // sometimes error occurred here,"Error Decrypting Data"
  33.            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(oldFileName, true);
  34.            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = doc;
  35.  
  36.            //System.Threading.Thread.Sleep(3000);
  37.  
  38.            var db = doc.Database;
  39.  
  40.            using (doc.LockDocument())
  41.            {
  42.                ObjectId layoutId = new ObjectId();
  43.                using (Transaction tr = db.TransactionManager.StartTransaction())
  44.                {
  45.                    LayoutManager lm = LayoutManager.Current;
  46.                    // ACAD_LAYOUT dictionary.
  47.                    DBDictionary layoutDict = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
  48.                    // Iterate dictionary entries.
  49.                    foreach (DBDictionaryEntry de in layoutDict)
  50.                    {
  51.                        string layoutName = de.Key;
  52.                        if (layoutName != "Model")
  53.                        {
  54.                            layoutId = lm.GetLayoutId(layoutName);
  55.                            lm.CurrentLayout = layoutName;
  56.                            break;
  57.                        }
  58.                    }
  59.                    tr.Commit();
  60.                }
  61.  
  62.                Autodesk.AutoCAD.ExportLayout.Engine engine = Autodesk.AutoCAD.ExportLayout.Engine.Instance();
  63.  
  64. //sometimes carash here, ePermanentlyErased error occurred
  65.                using (Database Outdb = engine.ExportLayout(layoutId))
  66.                {
  67.                    if (engine.EngineStatus != AcExportLayout.ErrorStatus.Succeeded)
  68.                    {
  69.                        Arx.Prompts.Editor.WriteMessage("\nExportLayout failed: ", engine.EngineStatus.ToString());
  70.                        return;
  71.                    }
  72.                    else
  73.                    {
  74.                        Outdb.SaveAs(newFileName, DwgVersion.AC1800);
  75.                    }
  76.                }
  77.            }
  78.            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.CloseAndDiscard();
  79.  
  80.            //System.Threading.Thread.Sleep(3000);
  81.  
  82.        }
« Last Edit: September 07, 2017, 09:44:34 pm by netcai »

FriendFromArea51

  • Swamp Rat
  • Posts: 682
  • Mars sucks!
Re: exportlayout
« Reply #1 on: September 08, 2017, 01:23:11 am »
Hi Netcai,

Is this the same issue here:

https://www.theswamp.org/index.php?topic=53412.0

Believe it mentions he exportlayout class is undocumented. It will be difficult for people to find time to troubleshoot it for you if that's the case. 

There are other ways to export information to new drawings... might search "autocad .net save objects to new drawing"  or something along those lines.

netcai

  • Mosquito
  • Posts: 8
Re: exportlayout
« Reply #2 on: September 08, 2017, 04:18:46 am »
yes, it's the same problem, I have searched whole forum,but cann't find a method to export many layouts by side database,so I have no choice to use active document ,but repeated open and close documents will cause the problem Mentioned above

dgorsman

  • Water Moccasin
  • Posts: 2243
Re: exportlayout
« Reply #3 on: September 08, 2017, 10:10:08 am »
Maybe work the other way around - copy the actual file and delete unwanted layouts.  That should be possible with a side database, may even be possible through the core console.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

T.Willey

  • Needs a day job
  • Posts: 5189
Re: exportlayout
« Reply #4 on: September 08, 2017, 02:03:32 pm »
Not a .Net solution, but here is a lisp routine that will export layouts to new drawings.  It can be used on a different drawing than the current one.  Hope it can work as a possible solution until you find a .Net one.

https://www.theswamp.org/index.php?topic=52709.0
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.