DocumentCollection acDocMgr = App.DocumentManager;
Document doc = acDocMgr.Open(file, false);
Database db = doc.Database;
Editor ed = doc.Editor;
using (DocumentLock acLckDoc = doc.LockDocument())
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
if (ids.Count != 0)
{
IdMapping iMap = new IdMapping();
db.WblockCloneObjects(ids, db.BlockTableId, iMap, DuplicateRecordCloning.Ignore, false);
}
var layers = GetLayers(trans, db);
var linetypes = GetLinetypes(trans, db);
foreach (BlockReference br in blocks[file])
{
if (!layers.ContainsKey(br.Layer))
LoadLayer(Layers[br.Layer], db, trans);
if (!linetypes.ContainsKey(br.Linetype))
LoadLinetype(Linetypes[br.Linetype], db, trans);
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
BlockTableRecord blockDef = bt[br.Name].GetObject(OpenMode.ForRead) as BlockTableRecord;
BlockTableRecord ms = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord;
Point3d point = br.Position;
using (BlockReference blockRef = new BlockReference(point, blockDef.ObjectId))
{
blockRef.ScaleFactors = br.ScaleFactors;
blockRef.LinetypeScale = br.LinetypeScale;
blockRef.Layer = br.Layer;
blockRef.Linetype = br.Linetype;
blockRef.Rotation = br.Rotation;
blockRef.BlockTransform = br.BlockTransform;
blockRef.Color = br.Color;
blockRef.LineWeight = br.LineWeight;
blockRef.Material = br.Material;
ms.AppendEntity(blockRef);
trans.AddNewlyCreatedDBObject(blockRef, true);
}
}
trans.Commit();
}
}