[CommandMethod("ImportDrawing", CommandFlags.Session)]
public static void ImportDrawing()
{
ObjectIdCollection copiedIds = new ObjectIdCollection();
using (var referenceDB = new Database(false, true))
{
string destFileName = @"C:\test\test1.dwg";
referenceDB.ReadDwgFile(destFileName, FileShare.Read, false, "");
referenceDB.CloseInput(true);
using (Transaction tr = referenceDB.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(referenceDB.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord ms = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId id in ms)
{
copiedIds.Add(id);
}
tr.Commit();
}
}
Document currentdoc = Application.DocumentManager.MdiActiveDocument;
Database currentDB = currentdoc.Database;
Editor editor = currentdoc.Editor;
PromptPointOptions ppo = new PromptPointOptions("\nВыберите точку вставки: ");
PromptPointResult ppr = editor.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
return;
using (DocumentLock acLckDoc = currentdoc.LockDocument())
{
using (Transaction tr2 = currentDB.TransactionManager.StartTransaction())
{
BlockTable bt2 = tr2.GetObject(currentDB.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord ms2 = tr2.GetObject(bt2[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
var idMapping = new IdMapping();
currentDB.WblockCloneObjects(copiedIds, currentDB.BlockTableId, idMapping,
DuplicateRecordCloning.Replace, false);
tr2.Commit();
}
}
}