deleteObjs(TypedValue[] TVs) { SelectionSet ss = Select.buildSSetBase(TVs, true); if (ss == null) { return; } try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId idObj in ss.GetObjectIds()) { Entity ENT = (Entity)idObj.GetObject(OpenMode.ForWrite, true); ENT.Erase(); } tr.Commit(); } // end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 458"); } }
deleteObjs(ObjectId[] ids) { try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId idObj in ids) { try { Entity ENT = (Entity)idObj.GetObject(OpenMode.ForWrite); ENT.Erase(); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 503"); } } tr.Commit(); } // end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 511"); } }
deleteObjs(TypedValue[] TVs, Point3d pnt3dLL, Point3d pnt3dUR) { ObjectId[] ids; SelectionFilter filter = new SelectionFilter(TVs); PromptSelectionResult PSR = BaseObjs._editor.SelectCrossingWindow(pnt3dLL, pnt3dUR, filter); if (PSR.Status == PromptStatus.OK) { ids = PSR.Value.GetObjectIds(); } else { return; } try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId idObj in ids) { Entity ENT = (Entity)idObj.GetObject(OpenMode.ForWrite, true); ENT.Erase(); } tr.Commit(); } // end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 433"); } }
explode(this ObjectId[] ids) { ObjectIdCollection idsEx = new ObjectIdCollection(); using (Transaction tr = BaseObjs.startTransactionDb()) { for (int i = 0; i < ids.Length; i++) { try { Entity ent = (Entity)tr.GetObject(ids[i], OpenMode.ForWrite); DBObjectCollection dbObjs = new DBObjectCollection(); ent.Explode(dbObjs); ent.Erase(); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(BaseObjs._db.CurrentSpaceId, OpenMode.ForWrite); foreach (DBObject dbObj in dbObjs) { Entity entX = (Entity)dbObj; idsEx.Add(ms.AppendEntity(entX)); tr.AddNewlyCreatedDBObject(entX, true); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 390"); } } tr.Commit(); } return(idsEx); }
deleteObj(ObjectId objID) { Entity ent = null; try { using (BaseObjs._acadDoc.LockDocument()) { using (Transaction tr = BaseObjs.startTransactionDb()) { if (objID.IsValid && !objID.IsEffectivelyErased && !objID.IsErased) { try { DBObject dbObj = (DBObject)tr.GetObject(objID, OpenMode.ForWrite); if (dbObj is Entity) { ent = (Entity)dbObj; if (ent != null) { ent.Erase(true); } } else { dbObj.Erase(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 393"); } } else { return; } tr.Commit(); } // end using } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 404"); } }
explode(this ObjectId id) { ObjectIdCollection ids = new ObjectIdCollection(); using (Transaction tr = BaseObjs.startTransactionDb()) { Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite); DBObjectCollection dbObjs = new DBObjectCollection(); ent.Explode(dbObjs); ent.Erase(); BlockTable bt = (BlockTable)tr.GetObject(BaseObjs._db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); foreach (DBObject dbObj in dbObjs) { Entity entX = (Entity)dbObj; ids.Add(ms.AppendEntity(entX)); tr.AddNewlyCreatedDBObject(entX, true); } tr.Commit(); } return(ids); }
private void DeletePoly2D3DObjects(string source, string dest, string drawingName) { bool eraseOrig = true; try { if (drawingName == null) { throw new ArgumentNullException(nameof(drawingName)); } _logger.AddLog(String.Format("Drawing to Open: {0}", source)); Autodesk.AutoCAD.DatabaseServices.Database oldDb = HostApplicationServices.WorkingDatabase; using (Autodesk.AutoCAD.DatabaseServices.Database db = new Autodesk.AutoCAD.DatabaseServices.Database(false, true)) { db.ReadDwgFile(source, FileOpenMode.OpenForReadAndWriteNoShare, true, null); db.CloseInput(true); HostApplicationServices.WorkingDatabase = db; using (Transaction tr = db.TransactionManager.StartTransaction()) { // Collect our exploded objects in a single collection var selected = BBC.Common.AutoCAD.AcadUtilities. GetAllObjectIdsInModel(db, false); DBObjectCollection objs = new DBObjectCollection(); // Loop through the selected objects foreach (ObjectId so in selected) { // Open one at a time Entity ent = (Entity)tr.GetObject( so, OpenMode.ForRead ); ; if (ent.GetType() == typeof(Polyline3d) || ent.GetType() == typeof(Polyline2d) || ent.GetType() == typeof(Acad.Polyline) || ent.GetType() == typeof(Line)) { if (eraseOrig) { ent.UpgradeOpen(); ent.Erase(); } } } tr.Commit(); } var output = Path.Combine(_sdir, "S-" + drawingName + ".DWG"); var dxfout = output.Replace(".DWG", ".DXF"); db.SaveAs(output, DwgVersion.Current); HostApplicationServices.WorkingDatabase = oldDb; db.DxfOut(dxfout, 16, DwgVersion.Current); } } catch (Exception ex) { _logger.LogException(ex); } }