如何把一个层上的所有自定义的块复制到另一层上去?
<p><font face="Verdana">请版主帮忙!下面的方式执行完后,在新层上创建时实体都不可见,用CTRL+A可以选择到自定义的实体,但属性显示在多个层上。求助</font></p><p><font face="Verdana">List<BlockReference> newBrs = new List<BlockReference>();</font></p>
<p><font face="Verdana"> using (Transaction trans = db.TransactionManager.StartTransaction())<br/> {<br/> BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;<br/> BlockTableRecord btr = trans.GetObject(bt, OpenMode.ForRead) as BlockTableRecord;</font></p>
<p><font face="Verdana"> foreach (ObjectId id in btr)<br/> {<br/> Entity ent = trans.GetObject(id, OpenMode.ForRead, false) as Entity;<br/> if (ent.GetType() == typeof(BlockReference))<br/> {<br/> BlockReference oldBr = ent as BlockReference;<br/> if (oldBr.Name == "MyBlock1" || oldBr.Name == "MyBlock2" )<br/> {<br/> //BlockReference newBr = new BlockReference(oldBr.Position, oldBr.BlockTableRecord);<br/> BlockReference newBr = oldBr.Clone()as BlockReference;<br/> newBr.Layer = assignedLayerName;<br/> newBr.Visible = true;<br/> newBrs.Add(newBr);<br/> }<br/> }<br/> }<br/> trans.Commit();<br/> }<br/> //在新层添加所有实体<br/> using (Transaction trans = db.TransactionManager.StartTransaction())<br/> {<br/> //选择所有道路节点实体<br/> BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;<br/> BlockTableRecord btr = trans.GetObject(bt, OpenMode.ForWrite) as BlockTableRecord;</font></p>
<p><font face="Verdana"> for (int i = 0; i < newBrs.Count; i++)<br/> {<br/> btr.AppendEntity(newBrs);<br/> trans.AddNewlyCreatedDBObject(newBrs, true);<br/> }<br/> trans.Commit();<br/> }<br/> }</font></p>
public void test24()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptSelectionResult res =
ed.SelectAll(
new SelectionFilter(
new TypedValue[]
{
new TypedValue(0, "insert"),
new TypedValue(2, "MyBlock1,MyBlock2")
}));
if (res.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectIdCollection ids = new ObjectIdCollection(res.Value.GetObjectIds());
IdMapping idm = new IdMapping();
db.DeepCloneObjects(ids, db.CurrentSpaceId, idm, false);
foreach (IdPair idp in idm)
{
BlockReference blkref = tr.GetObject(idp.Value, OpenMode.ForWrite) as BlockReference;
if (blkref != null)
{
blkref.Layer = "0";
}
}
tr.Commit();
}
}
}
<p>版主:块是复制过去了,在两个层上都有,但是若关掉原始块所在的层,打开新层,则复制到新层的块不可见,也无法用鼠标选取,通过快速选择可以找到复制后的块。和原始的块定义有关吗?深度克隆后,克隆体(块)包含的成员与原来的块绑定在一起吗?望版主进一步指教。谢ing!</p> <p>你的块定义时,块内实体的图层是怎么定义的?</p> 本帖最后由 作者 于 2010-8-5 13:13:52 编辑 <br /><br /> <p><font face="Verdana">“第一版”:块内实体.Layer=自定义层1。</font><font face="Verdana">(实验后不行)。</font></p>
<p><font face="Verdana">“第二版”:现在0层上建块myblock1,然后删掉myblock1,再新建图层1,建块myblock1,然后运行程序,复制块myblock1到图层2,此时能够可见。但若直接新建图层1,建块myblock1,然后运行程序,复制块myblock1到图层2,此时则不可见。</font></p>
<p>呵呵,晕了!怎么能直接就看见哪?</p> <p>试下设置实体layer=byblock</p> 怎么指定哪?版主能给出个具体语法格式。 解决方案:创建块时,将块的层设置为“0”层,可解决此问题。 先学习了,
页:
[1]