public override bool WorldDraw(Drawable d, WorldDraw wd) { double radius = 0.0; if (d is DBObject) { radius = PipeRadiusForObject((DBObject)d); } if (radius > 0.0) { Line line = d as Line; if (line != null) { // Draw the line as is, with overruled attributes base.WorldDraw(line, wd); if (!line.Id.IsNull && line.Length > 0.0) { // Draw a pipe around the line EntityColor c = wd.SubEntityTraits.TrueColor; wd.SubEntityTraits.TrueColor = new EntityColor(0x00AfAfff); wd.SubEntityTraits.LineWeight = LineWeight.LineWeight000; Circle clr = new Circle( line.StartPoint, line.EndPoint - line.StartPoint, radius ); ExtrudedSurface pipe = new ExtrudedSurface(); try { pipe.CreateExtrudedSurface( clr, line.EndPoint - line.StartPoint, sweepOpts ); } catch { Document doc = Application.DocumentManager.MdiActiveDocument; doc.Editor.WriteMessage( "\nFailed with CreateExtrudedSurface." ); } clr.Dispose(); pipe.WorldDraw(wd); pipe.Dispose(); wd.SubEntityTraits.TrueColor = c; } return(true); } } return(base.WorldDraw(d, wd)); }
public override void Explode(Entity e, DBObjectCollection objs) { double radius = 0.0; if (e is DBObject) { radius = PipeDrawOverrule.PipeRadiusForObject(e); } if (radius > 0.0) { Line line = e as Line; if (line != null) { if (!line.Id.IsNull && line.Length > 0.0) { // Draw a pipe around the line Circle clr = new Circle( line.StartPoint, line.EndPoint - line.StartPoint, radius ); ExtrudedSurface pipe = new ExtrudedSurface(); try { pipe.CreateExtrudedSurface( clr, line.EndPoint - line.StartPoint, sweepOpts ); } catch { Document doc = Application.DocumentManager.MdiActiveDocument; doc.Editor.WriteMessage( "\nFailed with CreateExtrudedSurface." ); } clr.Dispose(); objs.Add(pipe); } return; } } base.Explode(e, objs); }
//aqcuired this information online, not sure how tall this surface is supposed to be or how to insert it into drawing //creates an extruded surface from an open polyline private ExtrudedSurface extrudeOpenPolyline(Polyline pPoly, Editor ed) { ExtrudedSurface extrSurf = new ExtrudedSurface(); Face face = new Face(pPoly.StartPoint, pPoly.EndPoint, pPoly.EndPoint + new Vector3d(0, 0, 1000), pPoly.StartPoint + new Vector3d(0, 0, 1000), true, true, true, true); Autodesk.AutoCAD.DatabaseServices.Surface sweepEnt = new Autodesk.AutoCAD.DatabaseServices.Surface(); sweepEnt.SetDatabaseDefaults(); try { sweepEnt = Autodesk.AutoCAD.DatabaseServices.Surface.CreateFrom(face); } catch (Autodesk.AutoCAD.Runtime.Exception e) {} SweepOptions sweepOpts = new SweepOptions(); try { extrSurf.CreateExtrudedSurface(sweepEnt, (pPoly.EndPoint - pPoly.StartPoint).GetPerpendicularVector(), sweepOpts); } catch { ed.WriteMessage("\nFailed with CreateExtrudedSurface."); } return(extrSurf); }
public static void UpdateSurface(ObjectId objectId, dynamic xb) { Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor; Document acDoc = acApp.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Point3d minPoint = new Point3d(Convert.ToDouble(xb.x1), Convert.ToDouble(xb.y1), Convert.ToDouble(xb.z1)); Point3d maxPoint = new Point3d(Convert.ToDouble(xb.x2), Convert.ToDouble(xb.y2), Convert.ToDouble(xb.z2)); using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table record 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; Point3d pStart = minPoint; Point3d pEnd = new Point3d(maxPoint.X, maxPoint.Y, minPoint.Z); Vector3d vec = new Vector3d(0, 0, maxPoint.Z - minPoint.Z); if (minPoint.Z == maxPoint.Z) { pStart = minPoint; pEnd = new Point3d(maxPoint.X, minPoint.Y, maxPoint.Z); vec = new Vector3d(0, maxPoint.Y - minPoint.Y, 0); } // Create polyline Polyline3d poly = new Polyline3d(); acBlkTblRec.AppendEntity(poly); acTrans.AddNewlyCreatedDBObject(poly, true); // Add vertex foreach (Point3d pnt in new List <Point3d>() { pStart, pEnd }) { PolylineVertex3d vex3d = new PolylineVertex3d(pnt); poly.AppendVertex(vex3d); acTrans.AddNewlyCreatedDBObject(vex3d, true); } poly.Closed = false; #if BRX_APP ExtrudedSurface extrSurf = (Teigha.DatabaseServices.ExtrudedSurface)acTrans.GetObject(objectId, OpenMode.ForWrite); #elif ARX_APP ExtrudedSurface extrSurf = (Autodesk.AutoCAD.DatabaseServices.ExtrudedSurface)acTrans.GetObject(objectId, OpenMode.ForWrite); #endif extrSurf.SetDatabaseDefaults(); SweepOptions sweepOpts = new SweepOptions(); extrSurf.CreateExtrudedSurface(poly, vec, sweepOpts); extrSurf.UIsoLineDensity = 0; extrSurf.VIsoLineDensity = 0; extrSurf.Draw(); poly.Erase(); acTrans.Commit(); ed.UpdateScreen(); } }
public void ExtrudedSurfaceCommand() { var document = Application.DocumentManager.MdiActiveDocument; if (document == null) // don't bother doing anything else return; var extrudedSquareInputResult = GetExtrusionInputFromUser(); // convenience variables var width = extrudedSquareInputResult.Width; var height = extrudedSquareInputResult.Height; var depth = extrudedSquareInputResult.Depth; // create new lines based on user input var line1 = new Line(new Point3d(0, 0, 0), new Point3d(width, 0, 0)); var line2 = new Line(new Point3d(width, 0, 0), new Point3d(width, height, 0)); var line3 = new Line(new Point3d(width, height, 0), new Point3d(0, height, 0)); var line4 = new Line(new Point3d(0, height, 0), new Point3d(0, 0, 0)); // convenience list var lineList = new List<Line> { line1, line2, line3, line4 }; using (document.LockDocument()) { using (var database = document.Database) { using (var transaction = database.TransactionManager.StartTransaction()) { using (var currentSpace = (BlockTableRecord)transaction.GetObject(database.CurrentSpaceId, OpenMode.ForWrite)) { // add each line to current space and transaction then create an extruded surface from each with user supplied depth foreach (var line in lineList) { currentSpace.AppendEntity(line); transaction.AddNewlyCreatedDBObject(line, true); var extrudedSurface = new ExtrudedSurface(); extrudedSurface.CreateExtrudedSurface(line, new Vector3d(0, 0, depth), new SweepOptions()); currentSpace.AppendEntity(extrudedSurface); transaction.AddNewlyCreatedDBObject(extrudedSurface, true); } } transaction.Commit(); } } } }