public Curve NurbsToSpeckle(DB.NurbSpline revitCurve, string units = null) { var points = new List <double>(); foreach (var p in revitCurve.CtrlPoints) { var point = PointToSpeckle(p, units); points.AddRange(new List <double> { point.x, point.y, point.z }); } Curve speckleCurve = new Curve(); speckleCurve.weights = revitCurve.Weights.Cast <double>().ToList(); speckleCurve.points = points; speckleCurve.knots = revitCurve.Knots.Cast <double>().ToList();; speckleCurve.degree = revitCurve.Degree; //speckleCurve.periodic = revitCurve.Period; speckleCurve.rational = revitCurve.isRational; speckleCurve.closed = RevitVersionHelper.IsCurveClosed(revitCurve); speckleCurve.units = units ?? ModelUnits; speckleCurve.domain = new Interval(revitCurve.GetEndParameter(0), revitCurve.GetEndParameter(1)); speckleCurve.length = ScaleToSpeckle(revitCurve.Length); var coords = revitCurve.Tessellate().SelectMany(xyz => PointToSpeckle(xyz, units).ToList()).ToList(); speckleCurve.displayValue = new Polyline(coords, units); return(speckleCurve); }
private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.NurbSpline crv) { var convert = NurbsCurve.ByControlPointsWeightsKnots(crv.CtrlPoints.Select(x => x.ToPoint(false)).ToArray(), crv.Weights.Cast <double>().ToArray(), crv.Knots.Cast <double>().ToArray(), crv.Degree); if (!crv.IsBound) { return(convert); } // bound the curve parametric range // we first get the full parametric domain from the knots // note that some knots be negative and the domain may appear reversed var parms = crv.Knots.Cast <double>().ToList(); var fsp = parms.First(); var fep = parms.Last(); // obtain the full domain var fd = Math.Abs(fsp - fep); // these are the start and end parameters of the bound curve var sp = crv.GetEndParameter(0); var ep = crv.GetEndParameter(1); // get the normalized parameters for trim var nsp = Math.Abs(fsp - sp) / fd; var nep = Math.Abs(fsp - ep) / fd; // if there's no trimming to do, avoid it if (Math.Abs(nsp) < 1e-6 && Math.Abs(1 - nep) < 1e-6) { return(convert); } return(convert.TrimByParameter(nsp, nep)); }