/// <summary> /// 由底面中心点、高度、棱数和底面外接圆半径在UCS中创建棱柱 /// </summary> /// <param name="bottomCenPt">底面中心点</param> /// <param name="height">高度</param> /// <param name="sides">棱数</param> /// <param name="radius">底面外接圆半径</param> /// <returns>返回创建的棱柱的Id</returns> public static ObjectId AddPrism(Point3d bottomCenPt, double height, int sides, double radius) { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; if (Math.Abs(height) < 0.00001 || radius < 0.00001 || sides < 3 || sides > 32) { ed.WriteMessage("\n参数不当,创建棱柱失败!"); return(ObjectId.Null); } // 创建 Solid3d ent = new Solid3d(); ent.RecordHistory = true; ent.CreatePyramid(Math.Abs(height), sides, radius, radius); // 位置调整 Point3d cenPt = bottomCenPt + new Vector3d(0.0, 0.0, 0.5 * height); Matrix3d mt = ed.CurrentUserCoordinateSystem; mt = mt * Matrix3d.Displacement(cenPt - Point3d.Origin); ent.TransformBy(mt); ObjectId entId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) { entId = db.AddToModelSpace(ent); tr.Commit(); } return(entId); }
public void Create3DBox() { Solid3d bbb = new Solid3d(); bbb.CreatePyramid(50, 3, 50, 0); bbb.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 250, 0); ToModelSpace(bbb); Solid3d bbbb = new Solid3d(); bbbb.CreateSphere(50); // Move(bbbb, new Point3d(-50, -50, -50)); ToModelSpace(bbbb); }