我是想实现从现有块复制来新建一个块,在新块中需更改原块的部分内容,代码如下:
- private ObjectId mCloneBlock(ObjectId oldBlockId,string sNewBlockName)
- {
- ObjectId newBlockId = ObjectId.Null;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForWrite) as BlockTable;
- BlockTableRecord btr=db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
- BlockTableRecord oldbtr=OldBlockId.GetObject(OpenMode.ForRead) as BlockTableRecord;
- IdMapping idmap=new IdMapping();
- BlockTableRecord newbtr = oldbtr.DeepClone(btr, idmap, false);
- foreach (ObjectId id in newbtr)
- {
- Entity ent = id.GetObject(OpenMode.ForRead) as Entity;
- if (ent != null)
- {
- ent.UpgradeOpen();
- ent.ColorIndex = 210;//更改实体颜色
- }
- }
- newbtr.Name = sNewBlockName;
- newBlockId = bt.Add(newbtr);
- tr.AddNewlyCreatedDBObject(newbtr, true);
- tr.Commit();
- }
- return newBlockId;
- }
但是更改之后原块的内容也被更改了,why?
|