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(); } }
AutoCAD.Net/C#.Net QQ群:193522571 删除编组(group) 尺寸线(dimension)
时间: 2024-10-01 07:35:51