Esempio n. 1
0
        static internal IEnumerable <Rhino.Geometry.Curve> GetPreviewWires(this IEnumerable <Autodesk.Revit.DB.GeometryObject> geometries)
        {
            var scaleFactor = Revit.ModelUnits;

            foreach (var geometry in geometries)
            {
                var gs = Revit.ActiveDBDocument.GetElement(geometry.GraphicsStyleId) as GraphicsStyle;

                if (geometry.Visibility != Visibility.Visible)
                {
                    continue;
                }

                switch (geometry)
                {
                case Autodesk.Revit.DB.GeometryInstance instance:
                    foreach (var g in instance.GetInstanceGeometry().GetPreviewWires())
                    {
                        yield return(g);
                    }
                    break;

                case Autodesk.Revit.DB.Solid solid:
                    if (solid.Faces.IsEmpty)
                    {
                        continue;
                    }

                    foreach (var edge in solid.Edges.OfType <Edge>())
                    {
                        var s = edge.AsCurve().ToRhino();

                        if (scaleFactor != 1.0)
                        {
                            s?.Scale(scaleFactor);
                        }

                        yield return(s);
                    }
                    break;

                case Autodesk.Revit.DB.Curve curve:
                    var c = curve.ToRhino();

                    if (scaleFactor != 1.0)
                    {
                        c?.Scale(scaleFactor);
                    }

                    yield return(c);

                    break;

                case Autodesk.Revit.DB.PolyLine polyline:
                    if (polyline.NumberOfCoordinates <= 0)
                    {
                        continue;
                    }

                    var p = new Rhino.Geometry.PolylineCurve(polyline.GetCoordinates().ToRhino());

                    if (scaleFactor != 1.0)
                    {
                        p?.Scale(scaleFactor);
                    }

                    yield return(p);

                    break;
                }
            }
        }
Esempio n. 2
0
        static internal IEnumerable <Rhino.Geometry.GeometryBase> ToRhino(this IEnumerable <Autodesk.Revit.DB.GeometryObject> geometries)
        {
            var scaleFactor = Revit.ModelUnits;

            foreach (var geometry in geometries)
            {
                switch (geometry)
                {
                case Autodesk.Revit.DB.GeometryInstance instance:
                    foreach (var g in instance.GetInstanceGeometry().ToRhino())
                    {
                        yield return(g);
                    }
                    break;

                case Autodesk.Revit.DB.Mesh mesh:
                    var m = mesh.ToRhino();
                    m.Faces.ConvertTrianglesToQuads(Revit.AngleTolerance, 0.0);

                    if (scaleFactor != 1.0)
                    {
                        m?.Scale(scaleFactor);
                    }

                    yield return(m);

                    break;

                case Autodesk.Revit.DB.Solid solid:
                    var s = solid.ToRhino();

                    if (scaleFactor != 1.0)
                    {
                        s?.Scale(scaleFactor);
                    }

                    yield return(s);

                    break;

                case Autodesk.Revit.DB.Curve curve:
                    var c = curve.ToRhino();

                    if (scaleFactor != 1.0)
                    {
                        c?.Scale(scaleFactor);
                    }

                    yield return(c);

                    break;

                case Autodesk.Revit.DB.PolyLine polyline:
                    var p = new Rhino.Geometry.PolylineCurve(polyline.GetCoordinates().ToRhino());

                    if (scaleFactor != 1.0)
                    {
                        p?.Scale(scaleFactor);
                    }

                    yield return(p);

                    break;
                }
            }
        }