李毛毛 发表于 2010-11-2 08:13:00

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();
            }
      }
为什么每次执行之后,都是当前的能够组正确,再执行一次,前面的组就被分解了,只有当前的是一个组????纠结了半天了,还没看出端倪来

雪山飞狐_lzh 发表于 2010-11-2 09:30:00

试下

                Group g = new Group();
                g.Append(ids);
                GroupDictionary.SetAt(name, g);
                Transaction.AddNewlyCreatedDBObject(g, true);

李毛毛 发表于 2010-11-2 10:50:00

还是不行,只要用一次,原来的就被分解了!!

雪山飞狐_lzh 发表于 2010-11-2 11:52:00

你的两次调用,name有变化么?

李毛毛 发表于 2010-11-2 13:09:00

没有变化!name是一个定值arrow,
ObjectIdCollection ocolls = new ObjectIdCollection();               
ocolls.Add(arrow.ObjectId);
                ocolls.Add(plxy.ObjectId);
                CreateGroup(ocolls, "arrow");

雪山飞狐_lzh 发表于 2010-11-2 15:36:00

改成CreateGroup(ocolls, "*");

李毛毛 发表于 2010-11-2 15:53:00

还是不行!!!郁闷啊!!

李毛毛 发表于 2010-11-5 16:55:00

没有别的方法了吗???这是什么情况呢??

雪山飞狐_lzh 发表于 2010-11-5 23:19:00

我的测试代码很正常哈


      
      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();
            }
      }

李毛毛 发表于 2010-11-8 09:30:00

可以了,可以了!!!太感谢了!!!!上次改的代码没有用到!!!!,真是麻烦了。太感谢了
页: [1]
查看完整版本: createGroup函数