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

Revit .NET API: WallCreation 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 WallCreation 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 WallCreation
    {
        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 List<ElementId> CreateSpiralWall(Document doc, Level level, XYZ location, XYZ normal, double minRadius, double increment, int rounds)
        {
            List<ElementId> ids = new List<ElementId>();

            for (int i = 0; i < 2 * rounds; i++)
            {
                double offset, radius, startAngle, endAngle;
                radius = minRadius + i * increment;
                offset = (i % 2 == 0 ? 0 : 1) * increment;
                startAngle = (i % 2 == 0 ? 0 : Math.PI);
                endAngle = (i % 2 == 0 ? Math.PI : Math.PI * 2);

                XYZ loc = new XYZ(location.X + offset, location.Y, location.Z);
                Arc arc1 = doc.Application.Create.NewArc(new Plane(normal, loc), radius, startAngle, endAngle);
                Wall wall = Wall.Create(doc, arc1, level.Id, false);
                ids.Add(wall.Id);
            }

            return ids;
        }

        public static List<ElementId> CreateRegularPolygonalWall(Document doc, Level level, XYZ location, XYZ normal, double radius, int sides)
        {
            List<ElementId> ids = new List<ElementId>();

            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);
                Wall wall = Wall.Create(doc, line, level.Id, false);
                ids.Add(wall.Id);
            }

            return ids;
        }

        public static List<ElementId> CreateSpringWall(Document doc, Level level, XYZ location, XYZ normal, double minRadius, double increment, int rounds)
        {
            List<ElementId> ids = new List<ElementId>();

            for (int i = 0; i < 2 * rounds; i++)
            {
                double offset, radius, startAngle, endAngle;
                radius = minRadius + i * increment;
                offset = (i % 2 == 0 ? 0 : 1) * increment;
                startAngle = (i % 2 == 0 ? 0 : Math.PI);
                endAngle = (i % 2 == 0 ? Math.PI : Math.PI * 2);

                XYZ loc = new XYZ(location.X + offset, location.Y, location.Z);
                Arc arc1 = doc.Application.Create.NewArc(new Plane(normal, loc), radius, startAngle, endAngle);
                Wall wall = Wall.Create(doc, arc1, level.Id, false);
                ids.Add(wall.Id);
            }

            return ids;
        }

        public static List<ElementId> CreateRoundWalls(Document doc, Level level, XYZ center, XYZ normal, double radius)
        {
            List<ElementId> walls = new List<ElementId>();

            Arc arc1 = doc.Application.Create.NewArc(new Plane(normal, center), radius, 0, Math.PI);
            Arc arc2 = doc.Application.Create.NewArc(new Plane(normal, center), radius, Math.PI, Math.PI * 2);

            Wall wall1 = Wall.Create(doc, arc1, level.Id, false);
            Wall wall2 = Wall.Create(doc, arc2, level.Id, false);

            walls.Add(wall1.Id);
            walls.Add(wall2.Id);

            return walls;
        }

    }


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