Author Topic: how to export lost of layouts?  (Read 2378 times)

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 12
how to export lost of layouts?
« on: September 03, 2017, 09:43:08 PM »
two problems:
1、I have lots of layouts in different drawings to export, how can I do it without open these drawings?
2、how to create a viewport without open the drawing?

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: how to export lost of layouts?
« Reply #1 on: September 03, 2017, 11:01:55 PM »
Sort of a lot of the API involved with those two particular tasks.   If you are simply trying to get viewports into another drawing (multiple even) you could right-click over the layout tab and use "import from template" and select the drawing you wish to import them from.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: how to export lost of layouts?
« Reply #2 on: September 04, 2017, 12:10:55 AM »
two problems:
1、I have lots of layouts in different drawings to export, how can I do it without open these drawings?
2、how to create a viewport without open the drawing?

2 questions:

1. Do you know how to export the layouts from a drawing you are working on in .net?
2. Can you create a viewport in a current drawing using .net?

If so you're halfway there, you can then just open the drawing database in memory (hint: Database.ReadDwgFile(...) ) and do you thing in the background with a bit of extra logic for multiple drawings.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

netcai

  • Mosquito
  • Posts: 12
Re: how to export lost of layouts?
« Reply #3 on: September 04, 2017, 03:25:27 AM »
2 questions:

1. Do you know how to export the layouts from a drawing you are working on in .net?
2. Can you create a viewport in a current drawing using .net?

yes,I use these methods on .net now,but when the numbuers of files is large,or the drawing size is very large,the code will become unstable,the same drawing, sometimes is ok, sometimes is wrong.So Iam trying to use side database,but many difference between using current drawing and side database:

the below code runs ok,but has two problem
1,only export the entities in model space,the entities on paper space don't export, I don't know why.
2,if has clipped block, the export block will restore its orional border, the clip state will disapeare.

public static void ExportLayoutSideDatabase(string oldFileName, string newFileName)
        {
            Database currentDatabase = HostApplicationServices.WorkingDatabase;
            using (Database db = new Database(false, true))
            {
                db.ReadDwgFile(oldFileName, System.IO.FileShare.ReadWrite, true, null);
                HostApplicationServices.WorkingDatabase = db;

                ObjectId layoutId = new ObjectId();
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    LayoutManager lm = LayoutManager.Current;
                    // ACAD_LAYOUT dictionary.
                    DBDictionary layoutDict = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
                    // Iterate dictionary entries.
                    foreach (DBDictionaryEntry de in layoutDict)
                    {
                        string layoutName = de.Key;
                        if (layoutName != "Model")
                        {
                            layoutId = lm.GetLayoutId(layoutName);
                            lm.CurrentLayout = layoutName;
                            break;
                        }
                    }

                    tr.Commit();
                }

                Autodesk.AutoCAD.ExportLayout.Engine engine = Autodesk.AutoCAD.ExportLayout.Engine.Instance();
                using (Database Outdb = engine.ExportLayout(layoutId))
                {
                    if (engine.EngineStatus != AcExportLayout.ErrorStatus.Succeeded)
                    {
                        Arx.Prompts.Editor.WriteMessage("\nExportLayout failed: ", engine.EngineStatus.ToString());
                        return;
                    }
                    else
                    {
                        Outdb.SaveAs(newFileName, DwgVersion.AC1800);
                    }
                }

                HostApplicationServices.WorkingDatabase = currentDatabase;
            }
        }
« Last Edit: September 04, 2017, 03:40:24 AM by netcai »

n.yuan

  • Bull Frog
  • Posts: 348
Re: how to export lost of layouts?
« Reply #4 on: September 04, 2017, 09:56:49 AM »
Just curious, where Autodesk.AutoCAD.ExportLayout.Engine class is from? At least I do not see it upto Acad2018 APIs. Which version of AutoCAD do you use?

Jeff H

  • Needs a day job
  • Posts: 6144
Re: how to export lost of layouts?
« Reply #5 on: September 04, 2017, 11:08:08 AM »
Just curious, where Autodesk.AutoCAD.ExportLayout.Engine class is from? At least I do not see it upto Acad2018 APIs. Which version of AutoCAD do you use?

https://www.theswamp.org/index.php?topic=44472.msg497326#msg497326

AcExportLayout.dll

n.yuan

  • Bull Frog
  • Posts: 348
Re: how to export lost of layouts?
« Reply #6 on: September 04, 2017, 02:33:44 PM »
Ah, thank, Jeff, for the link. Obviously, Autodesk.AutoCAD.ExportLayout is undocumented API, not intended for outsider to use. While I almost blindly trust any code from Tony, his example is for exporting from a document opened in Acad editor. We do not know if the ExportLayout namespace can be applied to side database or not. So, one can only use it with his/her own discretion: if it works, then works, if it is not, it is not. I do not think Autodesk, or anyone here, would be able to provide further detail/explanation on why the OP's code not working.

OTH, it is completely possible with formally available Acad .NET API to write code to export layout, which can be commented by anyone in the forum.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: how to export lost of layouts?
« Reply #7 on: September 04, 2017, 06:28:22 PM »
I never used it, other than looking at it with reflector and got some ideas for extension methods with it.