コード例 #1
0
ファイル: MyGroup.cs プロジェクト: 1833183060/autocad-dev
        /// <summary>
        /// 删除组内对象,并将组id记录到待删除变量
        /// 参考:https://www.cnblogs.com/swtool/p/3810009.html
        /// </summary>
        /// <param name="stropt"></param>

        public static void deleteGroupAndObjs(StringOption stropt)
        {
            if (erasingGroupId != ObjectId.Null)
            {
                return;
            }
            //定义数据库
            Database db = HostApplicationServices.WorkingDatabase;

            //获取当前文件
            //Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            //获取当前命令行对象
            //Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                #region  除组
                //定义组字典
                DBDictionary groupDict = (DBDictionary)db.GroupDictionaryId.GetObject(OpenMode.ForRead);
                //在组字典中搜索满足条件的组对象
                foreach (DictionaryEntry ide in groupDict)
                {
                    //获取组对象
                    Group partGroup = trans.GetObject((ObjectId)ide.Value, OpenMode.ForRead) as Group;
                    if (stropt.Match(partGroup.Name))
                    {
                        //partGroup.UpgradeOpen();
                        erasingGroupId = partGroup.ObjectId;
                        //partGroup.ObjectClosed += Group_ObjectClosed;

                        //先删除组中的对象再删除组,直接删除组的话只是将组打散而已
                        foreach (ObjectId id in partGroup.GetAllEntityIds())
                        {
                            try
                            {
                                Entity ent = (Entity)id.GetObject(OpenMode.ForWrite);
                                ent.Erase();
                                ent.Dispose();
                            }
                            catch (System.Exception ex) {
                                throw new System.Exception("128");
                            }
                        }
                        //partGroup.Close();
                        break;
                        //partGroup.UpgradeOpen();
                        //partGroup.Erase(true);
                        //partGroup.DowngradeOpen();
                    }
                }
                #endregion  除组
                trans.Commit();
            }

            erasingGroupId = ObjectId.Null;
        }
コード例 #2
0
ファイル: MyGroup.cs プロジェクト: 1833183060/autocad-dev
        public static Group getGroup(StringOption stropt, Transaction trans)
        {
            //定义数据库
            Database db = HostApplicationServices.WorkingDatabase;

            //定义组字典
            DBDictionary groupDict = (DBDictionary)trans.GetObject(db.GroupDictionaryId, OpenMode.ForRead);

            //在组字典中搜索满足条件的组对象
            foreach (DictionaryEntry ide in groupDict)
            {
                //获取组对象
                Group group = trans.GetObject((ObjectId)ide.Value, OpenMode.ForRead) as Group;

                if (stropt.Match(group.Name))
                {
                    return(group);
                }
            }
            return(null);
        }