当前位置: 代码迷 >> 综合 >> C#ObjectArx Cad删除实体
  详细解决方案

C#ObjectArx Cad删除实体

热度:90   发布时间:2023-12-17 03:57:19.0
        /// <summary>/// 删除当前模型空间上的实体。/// </summary>/// <param name="entityID">实体ID</param>/// <returns>true:成功 false:失败</returns>public static bool DelEntity(){try{Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CurrentDocument;using (DocumentLock docLock = doc.LockDocument())using (Database db = HostApplicationServices.WorkingDatabase){using (Transaction trans = db.TransactionManager.StartTransaction()){//获取块表BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));CadProjectInfo.IsManagerDelete = true;//管理员删除using (BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)){CadProjectInfo.keysLine.Clear();//清空管线集合CadProjectInfo.keysLineLabel.Clear();//清空管线标注集合CadProjectInfo.keysPoint.Clear();//清空管点集合CadProjectInfo.keysPointLabel.Clear();//清空管点标注集合CadProjectInfo.keysSparePoint.Clear();//清空多于点集合CadProjectInfo.keysSparePointLabel.Clear();//清空多余点标注集合CadProjectInfo.keysNoMeasurePoint.Clear();//清空未测管点集合CadProjectInfo.keysNoMeasurePointLabel.Clear();//清空未测管点标注集合CadProjectInfo.PipePointTagModes.Clear();//清空管点标注配置集合CadProjectInfo.PipeLineTagModes.Clear();//清空管线标注配置集合///上篇文件有讲到GetEntitiesInModelSpace()foreach (ObjectId id in GetEntitiesInModelSpace()){Entity entity = (Entity)trans.GetObject(id, OpenMode.ForWrite, true);if (entity == null || entity.IsErased == true || entity is ProxyEntity){continue;}entity.Erase(true);}}trans.Commit();CadProjectInfo.IsManagerDelete = false;//设置非管理员操作删除}}}catch (Exception ex){throw;}return true;}/// <summary>/// 删除多个实体。/// 删除当前模型空间上的实体。/// </summary>/// <param name="entityID">实体ID</param>/// <returns>true:成功 false:失败</returns>public static bool DelEntity(List<ObjectId> ids){try{Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CurrentDocument;using (DocumentLock docLock = doc.LockDocument())using (Database db = HostApplicationServices.WorkingDatabase){using (Transaction trans = db.TransactionManager.StartTransaction()){//获取块表BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));CadProjectInfo.IsManagerDelete = true;//管理员删除using (BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)){foreach (ObjectId id in ids){Entity entity = (Entity)trans.GetObject(id, OpenMode.ForWrite, true);if (entity == null || entity.IsErased == true || entity is ProxyEntity){continue;}entity.Erase(true);}}trans.Commit();CadProjectInfo.IsManagerDelete = false;//设置非管理员操作删除}}}catch (Exception ex){throw;}return true;}