Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Revit .NET API: RoofCreation Class Used by Non-Leaning Pisa Tower

$
0
0

We have programmatically created various Revit elements using the Revit .NET Creation APIs, specifically those New or Create methods. We also created a non-leaning Pisa Tower using all those Revit .NET Creation APIs that have been demonstrated in detail separately.  

Here is how the resultant Pisa Tower looks beautifully in Revit after being rendered.
 PisaTower
The RoofCreation class along with its useful methods have been fine tuned a bit when used to create the non-leaning Pisa Tower. Here is the latest code.

    public class RoofCreation
    {
        public static IOrderedEnumerable<Level> FindAndSortLevels(RvtDocument doc)
        {
            return new FilteredElementCollector(doc)
                            .WherePasses(new ElementClassFilter(typeof(Level), false))
                            .Cast<Level>()
                            .OrderBy(e => e.Elevation);
        }

        public static IEnumerable<RoofType> FindRoofTypes(RvtDocument doc)
        {
            return new FilteredElementCollector(doc)
                            .WherePasses(new ElementClassFilter(typeof(RoofType), false))
                            .Cast<RoofType>();
        }

        public static RoofBase CreateRoundRoof(Document doc, Level level, RoofType rooftype,
                                                    XYZ location, XYZ normal, double radius,
                                                    double slopeangle, double offset)
        {
            CurveArray profile = new CurveArray();
            Arc arc1 = doc.Application.Create.NewArc(new Plane(normal, location), radius, 0, Math.PI);
            Arc arc2 = doc.Application.Create.NewArc(new Plane(normal, location), radius, Math.PI, 2 * Math.PI);
            profile.Append(arc1);
            profile.Append(arc2);

            ModelCurveArray curveArrayMapping = new ModelCurveArray();
            FootPrintRoof roof = doc.Create.NewFootPrintRoof(profile, level, rooftype, out curveArrayMapping);

            foreach (ModelCurve curve in curveArrayMapping)
            {
                roof.set_DefinesSlope(curve, true);
                roof.set_SlopeAngle(curve, slopeangle);
                roof.set_Offset(curve, offset);
            }

            return roof;
        }

        public static RoofBase CreateRegularPolygonalRoof(Document doc, Level level, RoofType rooftype,
                                                            XYZ location, double radius, int sides,
                                                            double slopeangle, double offset)
        {
            CurveArray profile = new CurveArray();
            for (int i = 0; i < sides; i++)
            {
                double curAngle = i * Math.PI / sides * 2;
                double nextAngle = (i < sides - 1 ? i + 1 : 0) * Math.PI / sides * 2;

                XYZ curVertex = new XYZ(location.X + radius * Math.Cos(curAngle), location.Y + radius * Math.Sin(curAngle), location.Z);
                XYZ nextVertex = new XYZ(location.X + radius * Math.Cos(nextAngle), location.Y + radius * Math.Sin(nextAngle), location.Z);
                Line line = doc.Application.Create.NewLineBound(curVertex, nextVertex);

                profile.Append(line);
            }

            ModelCurveArray curveArrayMapping = new ModelCurveArray();
            FootPrintRoof roof = doc.Create.NewFootPrintRoof(profile, level, rooftype, out curveArrayMapping);

            foreach (ModelCurve curve in curveArrayMapping)
            {
                roof.set_DefinesSlope(curve, true);
                roof.set_SlopeAngle(curve, slopeangle);
                roof.set_Offset(curve, offset);
            }

            return roof;
        }
    }


Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.


Viewing all articles
Browse latest Browse all 872

Trending Articles