public static DesignBody CreatePolygon(IList <Point> inputPoints, double thickness, IPart part) { Plane plane; if (!AddInHelper.TryCreatePlaneFromPoints(inputPoints, out plane)) { throw new ArgumentException("Points don't form plane"); } return(CreatePolygon(inputPoints, plane, thickness, part)); }
public static Body CreateRevolvedCurve(Line axis, ITrimmedCurve curve) { Point point = curve.Geometry.Evaluate(curve.Bounds.Middle()).Point; Debug.Assert(Accuracy.LengthIsPositive((axis.ProjectPoint(point).Point - point).Magnitude)); Plane plane = null; bool success = AddInHelper.TryCreatePlaneFromPoints(new Point[] { axis.Origin, axis.Evaluate(1).Point, point }, out plane); Debug.Assert(success, "Could not create plane through points."); Point axisStart = axis.ProjectPoint(curve.StartPoint).Point; Point axisEnd = axis.ProjectPoint(curve.EndPoint).Point; var profile = new List <ITrimmedCurve>(); profile.Add(curve); if (axisStart != curve.StartPoint) { profile.Add(CurveSegment.Create(axisStart, curve.StartPoint)); } if (axisEnd != curve.EndPoint) { profile.Add(CurveSegment.Create(axisEnd, curve.EndPoint)); } profile.Add(CurveSegment.Create(axisStart, axisEnd)); try { Body body = Body.SweepProfile(Plane.PlaneZX, profile, new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) }); body.DeleteFaces(body.Faces.Where(f => f.Geometry is Plane).ToArray(), RepairAction.None); return(body); } catch { return(null); } }
public static Body CreatePolygon(IList <Point> inputPoints, Plane plane, double thickness) { List <ITrimmedCurve> profile = new List <ITrimmedCurve>(); if (plane == null) { if (!AddInHelper.TryCreatePlaneFromPoints(inputPoints, out plane)) { return(null); } } Point newPoint; Point lastPoint = inputPoints[inputPoints.Count - 1].ProjectToPlane(plane); List <Point> points = new List <Point>(); foreach (Point point in inputPoints) { newPoint = point.ProjectToPlane(plane); if (!Accuracy.Equals(newPoint, lastPoint)) { points.Add(newPoint); lastPoint = newPoint; } } for (int i = 0; i < points.Count; i++) { if (i < points.Count - 1) { profile.Add(CurveSegment.Create(points[i], points[i + 1])); } else { profile.Add(CurveSegment.Create(points[i], points[0])); } } Body body = null; try { if (thickness == 0) { body = Body.CreatePlanarBody(plane, profile); } else { body = Body.ExtrudeProfile(plane, profile, thickness); } } catch { string error = "Exception thrown creating planar body:\n"; foreach (Point point in inputPoints) { error += string.Format("{0}, {1}, {2}\n", point.X, point.Y, point.Z); } Debug.Assert(false, error); } if (body == null) { Debug.Fail("Profile was not connected, not closed, or not in order."); return(null); } return(body); }