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

Revit .NET Creations API: Create Regular Polygonal Floor

$
0
0

In Revit .NET API 2013, though the NewWall method has been moved to the Wall class itself, the NewFloor method has not. It is still in the Document.Create instance. Anyway, we figured where it is and were able to create some floors.

In this article, let’s create a floor having a regular polygon shape such as regular pentagon and regular octagon. Here is the core help method.

    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 Floor CreateRegularPolygonalFloor(Document doc, Level level, XYZ location, XYZ normal, double radius, int sides)
    {
        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);
        }

        return doc.Create.NewFloor(profile, false);
    }

Here is some sample caller code:

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

Here are two such regular polygons in Revit.
 PolygonalFloors
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