• AutoCAD.Net/C#.Net QQ群:193522571 删除编组(group) 尺寸线(dimension)


            public void deleteDimension()
            {
                //定义数据库
                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)
                    {
                        //获取组对象
                        acadGroup partGroup = (acadGroup)trans.GetObject((ObjectId)ide.Value, OpenMode.ForRead);
                        //对于组名包含"PART-"或匿名组中包含实体数量为2的组进行删除动作
                        if (partGroup.Name.Contains("PART-") || (partGroup.IsAnonymous && partGroup.NumEntities == 2))
                        {
                            //先删除组中的对象再删除组,直接删除组的话只是将组打散而已
                            foreach (ObjectId id in partGroup.GetAllEntityIds())
                            {
                                Entity ent = (Entity)id.GetObject(OpenMode.ForWrite);
                                ent.Erase();
                                ent.Dispose();
                            }
                            partGroup.UpgradeOpen();
                            partGroup.Erase(true);
                            partGroup.DowngradeOpen();
                        }
                    }
                    #endregion 删除组
                    #region 删除尺寸线
                    TypedValueList values = new TypedValueList();
                    values.Add(0, typeof(Dimension).Name);
                    SelectionFilter filter = new SelectionFilter(values);
                    PromptSelectionResult psr = ed.SelectAll(filter);
                    if (psr.Status == PromptStatus.OK)
                    {
                        //Application.ShowAlertDialog(string.Format("被选中的尺寸线有{0}个!", psr.Value.Count));
                        foreach (ObjectId id in psr.Value.GetObjectIds())
                        {
                            Entity ent = (Dimension)id.GetObject(OpenMode.ForWrite);
                            ent.Erase();
                            ent.Dispose();
                        }
                    }
                    #endregion 删除尺寸线
                    trans.Commit();
                }
            }
  • 相关阅读:
    Linux系统-命令行快捷键
    Golang理解-Context包
    Golang理解-垃圾回收机制
    Linux系统-Systemd资源控制
    Linux系统-"cannot access Input/output error"
    Linux系统-ntpdate时间同步报错
    Golang理解-数组和切片
    Golang理解-位运算
    Golang理解-指针
    Maven配置,使用IntelliJ IDEA和Maven创建Java Web项目
  • 原文地址:https://www.cnblogs.com/swtool/p/3810009.html
Copyright © 2020-2023  润新知