public void EraseflatNotUsedDirectlyStart() { Database Db = Application.DocumentManager.MdiActiveDocument.Database; using (Transaction acTrans = Db.TransactionManager.StartTransaction()) { for (int i = 1; i < 7; i++) { Solid3d ent = acTrans.GetObject(solids_buff[i], OpenMode.ForWrite) as Solid3d; //ent.Visible = false; ent.Erase(); } acTrans.Commit(); } }
public void FinalflatNotUsedDirectlyStart() { Database Db = Application.DocumentManager.MdiActiveDocument.Database; using (Transaction acTrans = Db.TransactionManager.StartTransaction()) { BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(Db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Solid3d ent = acTrans.GetObject(solids_buff[0], OpenMode.ForWrite) as Solid3d; ent.Erase(); acTrans.Commit(); } }
/// <summary> /// TODO /// </summary> /// <param name="objIds"></param> /// <param name="acCurEd"></param> /// <param name="acCurDb"></param> internal static void UpdateChildren(ObjectId[] objIds, Editor acCurEd, Database acCurDb) { using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { foreach (var oId in objIds) { if (oId.IsErased) { continue; } var pSol = acTrans.GetObject(oId, OpenMode.ForRead) as Solid3d; if (pSol != null) { var eInfo = new EntInfo(pSol, acCurDb, acTrans); if (eInfo.ChildHandles.Count > 0) { foreach (var cHandle in eInfo.ChildHandles) { var objId = acCurDb.GetObjectId(false, cHandle, 0); if (objId == ObjectId.Null || objId.IsErased) { continue; } Solid3d cSol = null; try { cSol = acTrans.GetObject(objId, OpenMode.ForWrite) as Solid3d; } catch (Exception) { acCurEd.WriteMessage("\nChild was erased."); } if (cSol == null) { continue; } var cInfo = new EntInfo(cSol, acCurDb, acTrans); var pClone = pSol.Clone() as Solid3d; if (pClone == null) { continue; } pClone.TransformBy(eInfo.LayMatrix); acCurDb.AppendEntity(pClone); pClone.TopLeftTo(Point3d.Origin); pClone.TransformBy(cInfo.LayMatrix.Inverse()); pClone.TransformBy(Matrix3d.Displacement( pClone.GeometricExtents.MinPoint.GetVectorTo(cSol.GeometricExtents.MinPoint))); pClone.SwapIdWith(cSol.ObjectId, true, true); cSol.Erase(); cSol.Dispose(); } } else { acCurEd.WriteMessage("\nObject has no child objects attached."); } } } acTrans.Commit(); } }
static public void MeshFromSolid() { Utils.Utils.Init(); Document acDoc = acApp.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor ed = acDoc.Editor; while (true) { // Ask the user to select a solid PromptEntityOptions peo = new PromptEntityOptions("Select a 3D solid"); peo.SetRejectMessage("\nA 3D solid must be selected."); peo.AddAllowedClass(typeof(Solid3d), true); PromptEntityResult per = ed.GetEntity(peo); if (per.Status == PromptStatus.Cancel || per.Status == PromptStatus.Error) { Utils.Utils.End(); return; } using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table for read BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; // Open the Block table record Model space for write BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Solid3d sol = acTrans.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d; try { // Set mesh/faces properties MeshFaceterData mfd = new MeshFaceterData(); mfd.FaceterMeshType = 2; mfd.FaceterDevNormal = 40; mfd.FaceterDevSurface = 0.05; mfd.FaceterGridRatio = 0; mfd.FaceterMaxEdgeLength = 0; MeshDataCollection md = SubDMesh.GetObjectMesh(sol, mfd); // Create mesh SubDMesh mesh = new SubDMesh(); mesh.SetDatabaseDefaults(); mesh.SetSubDMesh(md.VertexArray, md.FaceArray, 0); mesh.Layer = sol.Layer; // Add mesh to DB acBlkTblRec.AppendEntity(mesh); acTrans.AddNewlyCreatedDBObject(mesh, true); // Delete solid object sol.Erase(true); acTrans.Commit(); } catch (System.Exception ex) { ed.WriteMessage("Exception: {0}", ex.Message); } } } }