createGroup函数
public void CreateGroup(ObjectIdCollection objIds, string groupName){
Group gp = new Group(groupName, true);
//创建名为groupName的组
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction ta = db.TransactionManager.StartTransaction()) //启动事务处理
{
DBDictionary dict = (DBDictionary)ta.GetObject(db.GroupDictionaryId, OpenMode.ForWrite,true); //获取组所在的"Group"字典
dict.SetAt(groupName, gp); //在"Group"字典中加入组对象
foreach (ObjectId thisId in objIds) //遍历传入的实体集合的ObjectId
{
gp.Append(thisId); //在组中加入ObjectId为thisId的实体
}
ta.AddNewlyCreatedDBObject(gp, true);
ta.Commit(); //提交事务处理
ta.Dispose();
}
}
为什么每次执行之后,都是当前的能够组正确,再执行一次,前面的组就被分解了,只有当前的是一个组????纠结了半天了,还没看出端倪来
试下
Group g = new Group();
g.Append(ids);
GroupDictionary.SetAt(name, g);
Transaction.AddNewlyCreatedDBObject(g, true);
还是不行,只要用一次,原来的就被分解了!!
你的两次调用,name有变化么?
没有变化!name是一个定值arrow,
ObjectIdCollection ocolls = new ObjectIdCollection();
ocolls.Add(arrow.ObjectId);
ocolls.Add(plxy.ObjectId);
CreateGroup(ocolls, "arrow");
改成CreateGroup(ocolls, "*");
还是不行!!!郁闷啊!! 没有别的方法了吗???这是什么情况呢??
我的测试代码很正常哈
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]