public static Solid3d Extrude(this Region reg) { var sol = new Solid3d(); sol.Extrude(reg, 2.0, 0.0); return(sol); }
/// <summary> /// 由截面面域、拉伸高度和拉伸角度创建拉伸体 /// </summary> /// <param name="region">截面面域</param> /// <param name="height">拉伸高度</param> /// <param name="taperAngle">拉伸角度</param> /// <returns>返回创建的拉伸体的Id</returns> public static ObjectId AddExtrudedSolid(Region region, double height, double taperAngle) { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; try { Solid3d ent = new Solid3d(); ent.Extrude(region, height, taperAngle); ObjectId entId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) { entId = db.AddToModelSpace(ent); tr.Commit(); } return(entId); } catch { ed.WriteMessage("\n参数不当,创建拉伸体失败!"); return(ObjectId.Null); } }
/// <summary> /// Gets the centroid of the region. /// </summary> /// <param name="reg">The instance to which the method applies.</param> /// <returns>The centroid of the region (WCS coordinates).</returns> public static Point3d Centroid(this Region reg) { using (Solid3d sol = new Solid3d()) { sol.Extrude(reg, 2.0, 0.0); return sol.MassProperties.Centroid - reg.Normal; } }
/// <summary> /// Gets the centroid of the region. /// </summary> /// <param name="reg">The instance to which the method applies.</param> /// <returns>The centroid of the region (WCS coordinates).</returns> public static Point3d Centroid(this Region reg) { using (Solid3d sol = new Solid3d()) { sol.Extrude(reg, 2.0, 0.0); return(sol.MassProperties.Centroid - reg.Normal); } }
private void _drawColumn() { var solidColumn = new Solid3d(); solidColumn.Extrude(Region, d, 0); AutoCadHelper.AppendAndAddToTransaction(solidColumn); }
public void ExtrudedSolidCommand() { var document = Application.DocumentManager.MdiActiveDocument; if (document == null) // don't bother doing anything else return; using (var polyline = new Polyline()) { var extrudedSquareInputResult = GetExtrusionInputFromUser(); // convenience variables var width = extrudedSquareInputResult.Width; var height = extrudedSquareInputResult.Height; var depth = extrudedSquareInputResult.Depth; // Using the polyline, we add vertices based on the user's input polyline.AddVertexAt(0, Point2d.Origin, 0.0, 0.0, 0.0); polyline.AddVertexAt(1, new Point2d(width, 0.0), 0.0, 0.0, 0.0); polyline.AddVertexAt(2, new Point2d(width, height), 0.0, 0.0, 0.0); polyline.AddVertexAt(3, new Point2d(0.0, height), 0.0, 0.0, 0.0); polyline.Closed = true; // add polyline to DBObjectCollection for us in creating region from curves using (var dbObjectCollection = new DBObjectCollection { polyline }) { using (var regionCollection = Region.CreateFromCurves(dbObjectCollection)) { using (var region = (Region)regionCollection[0]) { using (var solid = new Solid3d()) { // extrude the region to the depth the user specified solid.Extrude(region, depth, 0.0); using (document.LockDocument()) { using (var database = document.Database) { using (var transaction = database.TransactionManager.StartTransaction()) { // get the current space for appending our extruded solid using (var currentSpace = (BlockTableRecord)transaction.GetObject(database.CurrentSpaceId, OpenMode.ForWrite)) { currentSpace.AppendEntity(solid); } transaction.AddNewlyCreatedDBObject(solid, true); transaction.Commit(); } } } } } } } } }
private void _drawBeam() { const double angle = (Math.PI / 2); var solidBeam = new Solid3d(); solidBeam.Extrude(Region, d, 0); // Rotate along flange solidBeam.TransformBy(Matrix3d.Rotation(angle, Vector3d.XAxis, Point3d.Origin)); AutoCadHelper.AppendAndAddToTransaction(solidBeam); }
// 由截面面域、拉伸高度和拉伸角度创建拉伸体的函数. public static ObjectId AddExtrudedSolid(Region region, double height, double taperAngle) { try { Solid3d ent = new Solid3d(); ent.Extrude(region, height, taperAngle); ObjectId entId = AppendEntity(ent); return(entId); } catch { ObjectId nullId = ObjectId.Null; return(nullId); } }
// draw the 3-D drawing // nFlag: dimension control private void DrawSolidProfile(Plate pl, Point3d p0, int nFlag) { // Create Container for the curve, the region (face) DBObjectCollection curves = new DBObjectCollection(); // - Collection for the regions DBObjectCollection regions = new DBObjectCollection(); // Solid3d objects Solid3d plateSolid = new Solid3d(); Solid3d rectHole = new Solid3d(); // Rectangular Hole in the Center Point3d[] pt = new Point3d[26]; // geometry helpers Line[] ln = new Line[26]; // database objects // create points pt[0] = p0; pt[1] = new Point3d(p0.X + (pl.dW - pl.R1), p0.Y, p0.Z); pt[2] = new Point3d(p0.X + pl.dW, pl.R1, p0.Z); pt[3] = new Point3d(pt[1].X, pt[2].Y, p0.Z); pt[4] = new Point3d(pt[3].X, pt[3].Y + pl.L9, p0.Z); pt[5] = new Point3d(pt[4].X + pl.L2, pt[4].Y + pl.L8, p0.Z); pt[6] = new Point3d(pt[5].X, pt[5].Y + pl.L7, p0.Z); pt[7] = new Point3d(pt[4].X, pt[6].Y + pl.L6, p0.Z); pt[8] = new Point3d(pt[7].X, pt[7].Y + pl.L5, p0.Z); pt[9] = new Point3d(p0.X + pl.L3, pt[8].Y + pl.L4, p0.Z); pt[10] = new Point3d(p0.X, pt[9].Y, p0.Z); // symmetry - create points on negative x-axis int k = 9; for (int i = 11; i < 20; i++) { pt[i] = new Point3d(-pt[k].X, pt[k].Y, pt[k].Z); k--; } // create lines and store them into the database for (int i = 0; i < 20; i++) { if (i != 1 & i != 18) { ln[i] = new Line(pt[i], pt[(i + 1)]); ln[i].ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(ln[i]); } else if (i == 1) { double st_angle0 = 270 * (Math.PI / 180); double end_angle0 = 0; Arc a0 = new Arc(pt[3], pl.R1, st_angle0, end_angle0); a0.ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(a0); } else if (i == 18) { double st_angle1 = 180 * (Math.PI / 180); double end_angle1 = 270 * (Math.PI / 180); Arc a1 = new Arc(pt[17], pl.R1, st_angle1, end_angle1); a1.ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(a1); } else { continue; } } // Create the Region from the curves regions = Region.CreateFromCurves(curves); plateSolid.ColorIndex = pl.nColor[CONTOUR]; // Create the plate without the hole plateSolid.Extrude((Region)regions[0], pl.dT, 0.0); // draw points for centre hole curves.Clear(); pt[20] = new Point3d(p0.X + pl.R2, pt[3].Y + pl.R2, 0.0); pt[21] = new Point3d(pt[20].X, pt[7].Y - pl.R2, 0.0); pt[22] = new Point3d(-pt[20].X, pt[7].Y - pl.R2, 0.0); pt[23] = new Point3d(-(p0.X + pl.R2), pt[3].Y + pl.R2, 0.0); pt[24] = new Point3d(p0.X, pt[20].Y, 0.0); pt[25] = new Point3d(p0.X, pt[21].Y, 0.0); // draw lines for centre hole for (int i = 20; i < 24; i++) { if (i != 21 & i != 23) { ln[i] = new Line(pt[i], pt[(i + 1)]); ln[i].ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(ln[i]); } else if (i == 21) { double st_angle2 = 0; double end_angle2 = 180 * (Math.PI / 180); Arc a2 = new Arc(pt[25], pl.R2, st_angle2, end_angle2); a2.ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(a2); } else if (i == 23) { double st_angle3 = 180 * (Math.PI / 180); double end_angle3 = 0; Arc a3 = new Arc(pt[24], pl.R2, st_angle3, end_angle3); a3.ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(a3); } else { continue; } } // Create the Region from the curves (Rectangular Hole) regions = Region.CreateFromCurves(curves); rectHole.Extrude((Region)regions[0], pl.dT, 0.0); rectHole.ColorIndex = pl.nColor[HIDDEN]; // Substract the Hole Solid from the Rectangle plateSolid.BooleanOperation(BooleanOperationType.BoolSubtract, rectHole); // Add Solids into the Database AcTrans.Add(plateSolid); }
public static DBObject Create(this Grevit.Types.Slab s, Transaction tr) { try { BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); // Polyline acPoly = new Polyline(); //acPoly.SetDatabaseDefaults(); //int i = 0; DBObjectCollection objColl = new DBObjectCollection(); Point3dCollection ptcol = new Point3dCollection(); foreach (Grevit.Types.Loop loop in s.surface.profile) { foreach (Grevit.Types.Component p in loop.outline) ptcol = p.To3dPointCollection(); //Curve3dCollection collt = parse3dCurve(p); //acPoly.AppendVertex(new PolylineVertex3d(new Point3d(p.x, p.y, p.z))); //acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0); //i++; //foreach (Curve3d curve in collt) //{ // objColl.Add(Autodesk.AutoCAD.DatabaseServices.Curve.CreateFromGeCurve(curve)); //} } Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, ptcol, true); objColl.Add(face); //Polyline3d face = new Polyline3d(); //ETC... // or from your settings // Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, vertices, true); DBObjectCollection myRegionColl = new DBObjectCollection(); // create a single region Autodesk.AutoCAD.DatabaseServices.Region objreg = new Autodesk.AutoCAD.DatabaseServices.Region(); DBObjectCollection objRegions = new DBObjectCollection(); try { objRegions = Autodesk.AutoCAD.DatabaseServices.Region.CreateFromCurves(objColl); objreg = objRegions[0] as Autodesk.AutoCAD.DatabaseServices.Region; } catch (Autodesk.AutoCAD.Runtime.Exception ex) { // eInvalidInput exception Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Error: unable to create region collection:\n" + ex.Message); } //acPoly.Closed = true; //ms.AppendEntity(acPoly); //tr.AddNewlyCreatedDBObject(acPoly, true); //atrix3d mm = Matrix3d.Displacement(new Vector3d(0, 0, r.outline[0].z)); //acPoly.TransformBy(mm); //Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, ed.CurrentUserCoordinateSystem); //Slab slab = new Slab(); //slab.SetDatabaseDefaults(db); //slab.SetToStandard(db); //slab.Location = new Point3d(0, 0, 0); //slab.SetBaseProfile(myProfile, Matrix3d.Identity); //DBObjectCollection col = acPoly.GetOffsetCurves(0); //DBObjectCollection res = Region.CreateFromCurves(coll); //Region reg = res[0] as Region; Solid3d solid = new Solid3d(); solid.Extrude(objreg, s.height, s.slope); LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead); if (s.TypeOrLayer != "") { if (lt.Has(s.TypeOrLayer)) solid.LayerId = lt[s.TypeOrLayer]; } //if (ss.Has(r.family, tr)) slab.StyleId = ss.GetAt(r.family); ms.AppendEntity(solid); tr.AddNewlyCreatedDBObject(solid, true); return solid; } catch (Autodesk.AutoCAD.Runtime.Exception e) { } return null; }
// TODO: Port of existing code, requires refactoring immininently public void EstimateFFLFromSurface(CivSurface proposed) { Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { DBObject obj = acTrans.GetObject(this.BaseObject, OpenMode.ForWrite); //Need to add the temp line to create feature line from it BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; ObjectId perimId = FeatureLine.Create("plot" + PlotId, obj.ObjectId); FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine; perim.AssignElevationsFromSurface(proposed.Id, false); var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint); // TODO: Move to settings double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15; // TODO: Move to generation code //Ad the FFL Label // Create a multiline text object using (MText acMText = new MText()) { Solid3d Solid = new Solid3d(); DBObjectCollection coll = new DBObjectCollection(); coll.Add(obj); Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0); Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0); Solid.Dispose(); acMText.Location = centroid; acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3"); //acMText.Rotation = Rotation; acMText.Height = 8; acMText.Attachment = AttachmentPoint.MiddleCenter; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } // TODO: Move to generation code foreach (Point3d p in points) { using (MText acMText = new MText()) { Point3d insert = new Point3d(p.X, p.Y, 0); acMText.Location = insert; //Number of course int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f))); if (courses > 0) { acMText.Contents = courses + " Courses"; acMText.Height = 4; acMText.Attachment = AttachmentPoint.TopRight; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } } } //perim.Erase(); //obj.Erase(); acTrans.Commit(); } }
public void MyCommand() { if (!this.ShowDialog()) { return; } double num1 = 1.0; double num2 = 0.25; double num3 = this.m * (double)this.z; double da = (2.0 * num1 + (double)this.z) * this.m; double df = ((double)this.z - 2.0 * num1 - 2.0 * num2) * this.m; double db = num3 * Math.Cos(this.a * Math.PI / 180.0); Point3d point = this.GetPoint(); DateTime now1 = DateTime.Now; Circle circle1 = new Circle(point, Vector3d.get_ZAxis(), db / 2.0); Circle cir1 = new Circle(point, Vector3d.get_ZAxis(), da / 2.0); Circle circle2 = new Circle(point, Vector3d.get_ZAxis(), df / 2.0); Circle pitchCircle = new Circle(point, Vector3d.get_ZAxis(), num3 / 2.0); Point3dCollection point3dCollection = new Point3dCollection(); Polyline3d evolent1 = this.CreatEvolent(point, da, db, cir1); Polyline3d evolent2 = this.MirrorEvolent(evolent1, pitchCircle, point); Arc arc = this.CreatArc(point, evolent1, evolent2); Line line1 = new Line(point, ((Curve)evolent1).get_StartPoint()); Line line2 = new Line(point, ((Curve)evolent2).get_StartPoint()); DBObjectCollection objectCollection1 = new DBObjectCollection(); objectCollection1.Add((DBObject)evolent1); objectCollection1.Add((DBObject)evolent2); objectCollection1.Add((DBObject)line2); objectCollection1.Add((DBObject)line1); objectCollection1.Add((DBObject)arc); DBObjectCollection objectCollection2 = new DBObjectCollection(); Entity[] entityArray = this.ArrayPolar((Entity)(Region.CreateFromCurves(objectCollection1).get_Item(0) as Region), point, this.z, 2.0 * Math.PI); objectCollection1.Clear(); objectCollection1.Add((DBObject)circle2); Region region1 = Region.CreateFromCurves(objectCollection1).get_Item(0) as Region; foreach (Entity entity in entityArray) { Region region2 = entity as Region; if (DisposableWrapper.op_Inequality((DisposableWrapper)region2, (DisposableWrapper)null)) { region1.BooleanOperation((BooleanOperationType)0, region2); } } objectCollection1.Clear(); Circle circle3 = new Circle(point, Vector3d.get_ZAxis(), 0.15 * (df - 10.0)); objectCollection1.Add((DBObject)circle3); DBObjectCollection fromCurves = Region.CreateFromCurves(objectCollection1); region1.BooleanOperation((BooleanOperationType)2, fromCurves.get_Item(0) as Region); Solid3d solid3d = new Solid3d(); solid3d.Extrude(region1, this.h, 0.0); solid3d.BooleanOperation((BooleanOperationType)2, this.NewBox(point, this.h, df)); if (this.doDemo == "Y") { this.AddEntityToModelSpace((Entity)evolent1); this.AddEntityToModelSpace((Entity)evolent2); this.AddEntityToModelSpace((Entity)arc); this.AddEntityToModelSpace((Entity)line1); this.AddEntityToModelSpace((Entity)line2); this.AddEntityToModelSpace((Entity)(((RXObject)region1).Clone() as Region)); Thread.Sleep(this.delay * 5); } this.ZoomToEntity((Entity)solid3d); this.AddEntityToModelSpace((Entity)solid3d); DateTime now2 = DateTime.Now; this.ed.WriteMessage("\n耗时{0}。", new object[1] { (object)this.Elapsed(now1, now2) }); }
public void PlineToPlots() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; PromptSelectionOptions pso = new PromptSelectionOptions(); pso.SingleOnly = true; pso.RejectObjectsOnLockedLayers = true; PromptSelectionResult psr = acDoc.Editor.GetSelection(pso); if (psr.Status == PromptStatus.OK) { using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { CivSurface oSurface = null; //Get the target surface ObjectIdCollection SurfaceIds = CivilApplication.ActiveDocument.GetSurfaceIds(); foreach (ObjectId surfaceId in SurfaceIds) { CivSurface temp = surfaceId.GetObject(OpenMode.ForRead) as CivSurface; if (temp.Name == Civils.Constants.ProposedGroundName) { oSurface = temp; } } int plotCount = 0; foreach (SelectedObject so in psr.Value) { try { DBObject obj = acTrans.GetObject(so.ObjectId, OpenMode.ForWrite); if (obj is Curve) { plotCount++; //Polyline acPline = obj as Polyline; //Need to add the temp line to create feature line from it BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; ObjectId perimId = FeatureLine.Create("plot" + plotCount, obj.ObjectId); FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine; perim.AssignElevationsFromSurface(oSurface.Id, false); var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint); double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15; //Ad the FFL Label // Create a multiline text object using (MText acMText = new MText()) { Solid3d Solid = new Solid3d(); DBObjectCollection coll = new DBObjectCollection(); coll.Add(obj); Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0); Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0); Solid.Dispose(); acMText.Location = centroid; acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3"); //acMText.Rotation = Rotation; acMText.Height = 8; acMText.Attachment = AttachmentPoint.MiddleCenter; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } foreach (Point3d p in points) { using (MText acMText = new MText()) { Point3d insert = new Point3d(p.X, p.Y, 0); acMText.Location = insert; //Number of course int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f))); if (courses > 0) { acMText.Contents = courses + " Courses"; acMText.Height = 4; acMText.Attachment = AttachmentPoint.TopRight; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } } } //perim.Erase(); obj.Erase(); } else { acDoc.Editor.WriteMessage("Object is not a polyline\n"); } } catch (Autodesk.AutoCAD.Runtime.Exception e) { acDoc.Editor.WriteMessage(e.Message + "\n"); } catch (System.Exception e) { acDoc.Editor.WriteMessage(e.Message + "\n"); } } acTrans.Commit(); } } }
public static DBObject Create(this Grevit.Types.Slab s, Transaction tr) { try { BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); // Polyline acPoly = new Polyline(); //acPoly.SetDatabaseDefaults(); //int i = 0; DBObjectCollection objColl = new DBObjectCollection(); Point3dCollection ptcol = new Point3dCollection(); foreach (Grevit.Types.Loop loop in s.surface.profile) { foreach (Grevit.Types.Component p in loop.outline) { ptcol = p.To3dPointCollection(); } //Curve3dCollection collt = parse3dCurve(p); //acPoly.AppendVertex(new PolylineVertex3d(new Point3d(p.x, p.y, p.z))); //acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0); //i++; //foreach (Curve3d curve in collt) //{ // objColl.Add(Autodesk.AutoCAD.DatabaseServices.Curve.CreateFromGeCurve(curve)); //} } Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, ptcol, true); objColl.Add(face); //Polyline3d face = new Polyline3d(); //ETC... // or from your settings // Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, vertices, true); DBObjectCollection myRegionColl = new DBObjectCollection(); // create a single region Autodesk.AutoCAD.DatabaseServices.Region objreg = new Autodesk.AutoCAD.DatabaseServices.Region(); DBObjectCollection objRegions = new DBObjectCollection(); try { objRegions = Autodesk.AutoCAD.DatabaseServices.Region.CreateFromCurves(objColl); objreg = objRegions[0] as Autodesk.AutoCAD.DatabaseServices.Region; } catch (Autodesk.AutoCAD.Runtime.Exception ex) { // eInvalidInput exception Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Error: unable to create region collection:\n" + ex.Message); } //acPoly.Closed = true; //ms.AppendEntity(acPoly); //tr.AddNewlyCreatedDBObject(acPoly, true); //atrix3d mm = Matrix3d.Displacement(new Vector3d(0, 0, r.outline[0].z)); //acPoly.TransformBy(mm); //Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, ed.CurrentUserCoordinateSystem); //Slab slab = new Slab(); //slab.SetDatabaseDefaults(db); //slab.SetToStandard(db); //slab.Location = new Point3d(0, 0, 0); //slab.SetBaseProfile(myProfile, Matrix3d.Identity); //DBObjectCollection col = acPoly.GetOffsetCurves(0); //DBObjectCollection res = Region.CreateFromCurves(coll); //Region reg = res[0] as Region; Solid3d solid = new Solid3d(); solid.Extrude(objreg, s.height, s.slope); LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead); if (s.TypeOrLayer != "") { if (lt.Has(s.TypeOrLayer)) { solid.LayerId = lt[s.TypeOrLayer]; } } //if (ss.Has(r.family, tr)) slab.StyleId = ss.GetAt(r.family); ms.AppendEntity(solid); tr.AddNewlyCreatedDBObject(solid, true); return(solid); } catch (Autodesk.AutoCAD.Runtime.Exception e) { } return(null); }
public void makeCylinder() { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; string getPointMessage = "Pick the center point: "; Point3d ptCenter = getPointWith(getPointMessage, ed); if (ptCenter.IsEqualTo(new Point3d(-1, -1, -1))) { return; } // Get the radius of the cylinder. string radiusMessage = "Pick the radius of cylinder: "; int radius = getValueWith(radiusMessage, ed); if (radius == -1) { return; } // Get the height of the cylinder. string heightMessage = "Pick the height of the cylinder: "; int height = getValueWith(heightMessage, ed); if (height == -1) { return; } Database dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; using (Transaction trans = dwg.TransactionManager.StartTransaction()) { try { BlockTable blk = trans.GetObject(dwg.BlockTableId, OpenMode.ForWrite) as BlockTable; if (blk == null) { return; } Circle circle = new Circle(ptCenter, Vector3d.ZAxis, radius); // make region. DBObjectCollection dbObjCollec = new DBObjectCollection(); dbObjCollec.Add(circle); DBObjectCollection regionObjCollec = Region.CreateFromCurves(dbObjCollec); Solid3d solid3d = new Solid3d(); solid3d.Extrude((Region)regionObjCollec[0], height, 0.0); // append elements into database. BlockTableRecord blkRecord = trans.GetObject(blk[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; blkRecord.AppendEntity(solid3d); trans.AddNewlyCreatedDBObject(solid3d, true); trans.Commit(); } catch (System.Exception) { trans.Abort(); throw; } } }
/// <summary> /// Gets the centroid of the region. /// </summary> /// <param name="reg">The instance to which the method applies.</param> /// <returns>The centroid of the region (WCS coordinates).</returns> public static Point3d Centroid([NotNull] this Region reg) { using var sol = new Solid3d(); sol.Extrude(reg, 2.0, 0.0); return(sol.MassProperties.Centroid - reg.Normal); }