createGroup函数
<p><font face="Verdana"> public void CreateGroup(ObjectIdCollection objIds, string groupName)<br/> {<br/> Group gp = new Group(groupName, true);<br/> //创建名为groupName的组 <br/> Database db = HostApplicationServices.WorkingDatabase;<br/> using (Transaction ta = db.TransactionManager.StartTransaction()) //启动事务处理<br/> {<br/> DBDictionary dict = (DBDictionary)ta.GetObject(db.GroupDictionaryId, OpenMode.ForWrite,true); //获取组所在的"Group"字典 <br/> dict.SetAt(groupName, gp); //在"Group"字典中加入组对象<br/> foreach (ObjectId thisId in objIds) //遍历传入的实体集合的ObjectId<br/> {<br/> gp.Append(thisId); //在组中加入ObjectId为thisId的实体<br/> }<br/> ta.AddNewlyCreatedDBObject(gp, true);<br/> ta.Commit(); //提交事务处理<br/> ta.Dispose();<br/> }<br/> }</font></p><p>为什么每次执行之后,都是当前的能够组正确,再执行一次,前面的组就被分解了,只有当前的是一个组????纠结了半天了,还没看出端倪来</p> <p>试下</p>
<p> </p>
<p><font face="Verdana"> Group g = new Group();<br/> g.Append(ids);<br/> GroupDictionary.SetAt(name, g);<br/> Transaction.AddNewlyCreatedDBObject(g, true);<br/></font></p> <p>还是不行,只要用一次,原来的就被分解了!!</p> <p>你的两次调用,name有变化么? </p> <p>没有变化!name是一个定值arrow,</p>
<p><font face="Verdana">ObjectIdCollection ocolls = new ObjectIdCollection();</font><font face="Verdana"> </font></p>
<p><font face="Verdana"> ocolls.Add(arrow.ObjectId);<br/> ocolls.Add(plxy.ObjectId);<br/> CreateGroup(ocolls, "arrow");</font></p> <p>改成CreateGroup(ocolls, "*");</p> 还是不行!!!郁闷啊!! <p>没有别的方法了吗???这是什么情况呢??</p> 我的测试代码很正常哈
public static void test26()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
var resSel = ed.GetSelection();
if (resSel.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBDictionary groupDict = tr.GetObject(db.GroupDictionaryId, OpenMode.ForWrite) as DBDictionary;
Group g = new Group();
g.Append(new ObjectIdCollection(resSel.Value.GetObjectIds()));
groupDict.SetAt("*", g);
tr.AddNewlyCreatedDBObject(g, true);
tr.Commit();
}
}
可以了,可以了!!!太感谢了!!!!上次改的代码没有用到!!!!,真是麻烦了。太感谢了
页:
[1]
2