请版主帮忙!下面的方式执行完后,在新层上创建时实体都不可见,用CTRL+A可以选择到自定义的实体,但属性显示在多个层上。求助
List<BlockReference> newBrs = new List<BlockReference>();
using (Transaction trans = db.TransactionManager.StartTransaction()) { BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId id in btr) { Entity ent = trans.GetObject(id, OpenMode.ForRead, false) as Entity; if (ent.GetType() == typeof(BlockReference)) { BlockReference oldBr = ent as BlockReference; if (oldBr.Name == "MyBlock1" || oldBr.Name == "MyBlock2" ) { //BlockReference newBr = new BlockReference(oldBr.Position, oldBr.BlockTableRecord); BlockReference newBr = oldBr.Clone()as BlockReference; newBr.Layer = assignedLayerName; newBr.Visible = true; newBrs.Add(newBr); } } } trans.Commit(); } //在新层添加所有实体 using (Transaction trans = db.TransactionManager.StartTransaction()) { //选择所有道路节点实体 BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
for (int i = 0; i < newBrs.Count; i++) { btr.AppendEntity(newBrs); trans.AddNewlyCreatedDBObject(newBrs, true); } trans.Commit(); } } |