Message 1 of 1
FATAL ERROR: Duplicated Service Name: AdskExportLayoutPE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
im export layout to model and show some error, any have ideal for that? Thanks you !
My Code
[CommandMethod("EXPORTLAYOUT2Test", CommandFlags.Session)]
public static void ExportLayouts2()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var editor = doc.Editor;
try
{
if ((short)Application.GetSystemVariable("DWGTITLED") == 0)
{
editor.WriteMessage(
"\nCommand cannot be used on an unnamed drawing"
);
return;
}
string format =
Path.Combine(
Path.GetDirectoryName(doc.Name),
Path.GetFileNameWithoutExtension(doc.Name))
+ "_{0}.dwg";
Dictionary<string, ObjectId> layouts = null;
using (doc.LockDocument())
{
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
// Get the localized name of the model tab:
BlockTableRecord btr = (BlockTableRecord)
SymbolUtilityServices.GetBlockModelSpaceId(db)
.GetObject(OpenMode.ForRead);
Layout layout = (Layout)
btr.LayoutId.GetObject(OpenMode.ForRead);
string model = layout.LayoutName;
// Open the Layout dictionary:
IDictionary layoutDictionary = (IDictionary)
db.LayoutDictionaryId.GetObject(OpenMode.ForRead);
// Get the names and ids of all paper space layouts
// into a Dictionary<string,ObjectId>:
layouts = layoutDictionary.Cast<DictionaryEntry>()
.Where(e => ((string)e.Key) != model)
.ToDictionary(
e => (string)e.Key,
e => (ObjectId)e.Value);
tr.Commit();
}
Autodesk.AutoCAD.ExportLayout.Engine engine =
Autodesk.AutoCAD.ExportLayout.Engine.Instance();
Commands.FileCreatedChoice choice = Autodesk.AutoCAD.ExportLayoutUI.Commands.FileCreatedChoice.DoNotOpenFile;
using (new ManagedSystemVariable("CTAB"))
{
foreach (var entry in layouts)
{
if (entry.Key != "Layout1") return;
string filename = string.Format(format, entry.Key);
editor.WriteMessage("\nExporting {0} => {1}\n", entry.Key, filename);
Application.SetSystemVariable("CTAB", entry.Key);
using (Database database = engine.ExportLayout(entry.Value))
{
if (engine.EngineStatus == AcExportLayout.ErrorStatus.Succeeded)
{
database.SaveAs(filename, DwgVersion.Newest);
}
else
{
editor.WriteMessage("\nExportLayout failed: ",
engine.EngineStatus.ToString());
break;
}
}
}
}
}
}
catch (System.Exception ex)
{
#if DEBUG
editor.WriteMessage(ex.ToString());
#else
throw ex;
#endif
}
}
Chuong Ho