https://blog.csdn.net/aasswwe/article/details/40899759
private void Test() { // 获取当前文档和数据库 Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor ed = acDoc.Editor; //启动事务 using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { //使用选择过滤器定义选择集规则 TypedValue[] typedValue = new TypedValue[1]; //TestLayer为图层名字 DxfCode.LayerName为筛选类型 详情见下面的DXF组码 typedValue.SetValue(new TypedValue((int)DxfCode.LayerName, "TestLayer"), 0); SelectionFilter filter = new SelectionFilter(typedValue); //根据条件 选择当前空间内所有未锁定及未冻结的对象。 //从图形中选择对象有几种方式,详情见下表 PromptSelectionResult result = ed.SelectAll(filter); // 如果提示状态OK,表示已选择到对象 反之则没有对象 if (result.Status != PromptStatus.OK) { return; } SelectionSet acSSet = result.Value; // 遍历选择集内的对象 foreach (ObjectId id in acSSet.GetObjectIds()) { Entity hatchobj = acTrans.GetObject(id, OpenMode.ForWrite) as Entity; hatchobj.Erase();//删除 } acTrans.Commit(); } }