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

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 8
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?

FriendFromArea51

  • Swamp Rat
  • Posts: 682
  • Mars sucks!
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

  • Gator
  • Posts: 2948
  • I don't need a job, I need Money!!
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.
"A language that doesn’t have everything is actually easier to program in than some that do."

        — Dennis M. Ritchie

netcai

  • Mosquito
  • Posts: 8
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: 236
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: 5854
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: 236
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: 5854
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.