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

Revit .NET Creation APIs: Create Regular Polygonal Walls

$
0
0

Revit .NET API 2013 has moved the Wall Creation APIs to the Wall class as some static methods. It is nice as related stuffs are put together now. People do not have to dig here and there to find something looking simple and natural anymore.

We created some linear, curve, and round walls before, provided some nice help methods, and worked around some Revit .NET API issues accordingly. In this post, let’s create some regular polygonal walls. Here is the code regarding the creation of some regular polygonal walls.

    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> 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;
    }

Here is the caller code.

WallCreation.CreateRegularPolygonalWall(
    CachedDoc,
    WallCreation.FindAndSortLevels(CachedDoc).Last(),
    XYZ.Zero,
    new XYZ(0, 0, 1),
    10, 5);

WallCreation.CreateRegularPolygonalWall(
    CachedDoc,
    WallCreation.FindAndSortLevels(CachedDoc).Last(),
    XYZ.Zero,
    new XYZ(0, 0, 1),
    20, 6);

WallCreation.CreateRegularPolygonalWall(
    CachedDoc,
    WallCreation.FindAndSortLevels(CachedDoc).Last(),
    XYZ.Zero,
    new XYZ(0, 0, 1),
    30, 7);

WallCreation.CreateRegularPolygonalWall(
    CachedDoc,
    WallCreation.FindAndSortLevels(CachedDoc).Last(),
    XYZ.Zero,
    new XYZ(0, 0, 1),
    40, 8);

Here is the regular polygonal walls in the plan view.
 PolygonalWallsPlan
Here is the regular polygonal wallswall in the 3D view.
 PolygonalWalls3D
Revit Addin Wizard (RevitAddinWizard) provides a variety of 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