首页 > 代码库 > AutoCAD.Net/C#.Net QQ群:193522571 删除编组(group) 尺寸线(dimension)
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(); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。