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;
}
}