/// <summary> /// Convert a generic Circle to a Revit Curve /// </summary> /// <param name="crvCurve"></param> /// <returns></returns> private static Autodesk.Revit.DB.Curve Convert(Autodesk.DesignScript.Geometry.Curve crvCurve) { Autodesk.DesignScript.Geometry.Curve[] curves = crvCurve.ApproximateWithArcAndLineSegments(); if (curves.Length == 1) { //line or arc? var point0 = crvCurve.PointAtParameter(0.0); var point1 = crvCurve.PointAtParameter(1.0); var pointMid = crvCurve.PointAtParameter(0.5); if (point0.DistanceTo(point1) > 1e-7) { var line = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(point0, point1); if (pointMid.DistanceTo(line) < 1e-7) { return(Convert(line)); } } //then arc if (point0.DistanceTo(point1) < 1e-7) { point1 = crvCurve.PointAtParameter(0.9); } var arc = Autodesk.DesignScript.Geometry.Arc.ByThreePoints(point0, pointMid, point1); return(Convert(arc)); } return(Convert(crvCurve.ToNurbsCurve())); }
/// <summary> /// creates slices using a curve as the spine /// </summary> /// <param name="solid">Solid: geometry that is to be parsed</param> /// <param name="curve">Curve: defines the normal used to create cut planes perpendicular to parameter "plane". /// If curve is too short, it will be extended using built-in extend function</param> /// <param name="thickness">Thickness: the thickness of the slices, or the thickness of the material to be used for the assembly</param> /// <param name="spacing">Spacing: the distance between each slice</param> /// <returns>A newly-constructed Slicer object</returns> internal Slicer(Solid solid, Curve curve, double thickness, double spacing, double origin) { Solid = solid; Thickness = thickness; Spacing = spacing; Plane plane = Plane.ByOriginNormal(curve.StartPoint, curve.Normal); Curve curvePlanar = curve; if(!curve.IsPlanar) { plane = Plane.ByBestFitThroughPoints(curve.ToNurbsCurve().ControlPoints()); curvePlanar = curve.PullOntoPlane(plane); } CutPlanesPrimary.AddRange(GenerateCutPlanes(plane)); CutPlanesSecondary.AddRange(GenerateCutPlanes(curvePlanar, origin)); InitialGeometry = new List<Geometry>(1){curvePlanar}; }