Esempio n. 1
0
        /// <summary>
        /// Converts a List of Grevit Curves to Revit Curves
        /// </summary>
        /// <param name="document">Active Document</param>
        /// <param name="grevitCurves">List of Grevit Curves</param>
        /// <returns>List of Revit Curves</returns>
        public static List <Curve> GrevitCurvesToRevitCurves(Component component, CoordinatesOverride coords = null)
        {
            List <Curve> curvesOut = new List <Curve>();


            if (component.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line line = (Grevit.Types.Line)component;
                curvesOut.Add(Autodesk.Revit.DB.Line.CreateBound(line.from.ToXYZ(coords), line.to.ToXYZ(coords)));
            }
            else if (component.GetType() == typeof(Grevit.Types.Arc))
            {
                Grevit.Types.Arc arc = (Grevit.Types.Arc)component;
                curvesOut.Add(Autodesk.Revit.DB.Arc.Create(arc.center.ToXYZ(coords), arc.radius, arc.start, arc.end, XYZ.BasisX, XYZ.BasisY));
            }
            else if (component.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points curve3points = (Grevit.Types.Curve3Points)component;
                curvesOut.Add(Autodesk.Revit.DB.Arc.Create(curve3points.a.ToXYZ(coords), curve3points.c.ToXYZ(coords), curve3points.b.ToXYZ(coords)));
            }
            else if (component.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine pline = (Grevit.Types.PLine)component;

                for (int i = 0; i < pline.points.Count - 1; i++)
                {
                    curvesOut.Add(Autodesk.Revit.DB.Line.CreateBound(pline.points[i].ToXYZ(coords), pline.points[i + 1].ToXYZ(coords)));
                }
            }
            else if (component.GetType() == typeof(Spline))
            {
                Spline      spline = (Spline)component;
                IList <XYZ> points = new List <XYZ>();
                foreach (Grevit.Types.Point point in spline.controlPoints)
                {
                    points.Add(point.ToXYZ(coords));
                }
#if (Revit2015 || Revit2016 || Revit2017)
                NurbSpline ns = NurbSpline.Create(points, spline.weights);
#else
                NurbSpline ns = (NurbSpline)NurbSpline.CreateCurve(points, spline.weights);
#endif
                ns.isClosed = spline.isClosed;
                curvesOut.Add(ns);
            }


            return(curvesOut);
        }
Esempio n. 2
0
        /// <summary>
        /// Get Grevit Curve Component
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="referenceID"></param>
        /// <returns></returns>
        public static Component ToGrevitCurve(this Rhino.Geometry.Curve curve, string referenceID = "")
        {
            if (curve.IsArc(Rhino.RhinoMath.ZeroTolerance))
            {
                Rhino.Geometry.Arc a;
                if (curve.TryGetArc(out a))
                {
                    Curve3Points arc = new Curve3Points();
                    arc.a = curve.PointAtStart.ToGrevitPoint();
                    arc.b = curve.PointAt(0.5).ToGrevitPoint();
                    arc.c = curve.PointAtEnd.ToGrevitPoint();
                    arc.GID = referenceID;

                    return arc;
                }
            }
            else if (curve.IsPolyline())
            {
                Rhino.Geometry.Polyline pline;
                if (curve.TryGetPolyline(out pline))
                {
                    PLine arc = new PLine();
                    arc.points = new List<Grevit.Types.Point>();
                    foreach (Rhino.Geometry.Point3d pkt in pline)
                    {
                        arc.points.Add(pkt.ToGrevitPoint());
                    }
                    arc.closed = pline.IsClosed;
                    arc.GID = referenceID;
                    return arc;
                }
            }
            else if (curve.IsEllipse())
            {

                Curve3Points arc = new Curve3Points();
                arc.a = curve.PointAtStart.ToGrevitPoint();
                arc.b = curve.PointAt(0.5).ToGrevitPoint();
                arc.c = curve.PointAtEnd.ToGrevitPoint();
                arc.GID = referenceID;
                return arc;

            }
            else if (curve.GetType() == typeof(Rhino.Geometry.NurbsCurve))
            {
                Rhino.Geometry.NurbsCurve nc = (Rhino.Geometry.NurbsCurve)curve;
                Grevit.Types.Spline spline = new Grevit.Types.Spline();
                spline.controlPoints = new List<Grevit.Types.Point>();
                spline.weights = new List<double>();
                foreach (Rhino.Geometry.ControlPoint p in nc.Points)
                {
                    spline.controlPoints.Add(p.Location.ToGrevitPoint());
                    spline.weights.Add(p.Weight);
                }
                spline.degree = nc.Degree;
                spline.isClosed = nc.IsClosed;
                spline.isRational = nc.IsRational;
                spline.isPeriodic = nc.IsPeriodic;
                spline.GID = referenceID;
                spline.knots = new List<double>();
                foreach (double dbl in nc.Knots) spline.knots.Add(dbl);

                return spline;

            }
            else
            {
                Line arc = new Line();
                arc.from = curve.PointAtStart.ToGrevitPoint();
                arc.to = curve.PointAtEnd.ToGrevitPoint();
                arc.GID = referenceID;
                return arc;
            }

            return null;
        }