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

Revit .NET Creations API: Create Regular Polygonal Floor With Regular Polygonal Opening Inside

$
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 with a regular polygon shape opening inside such as  regular hexagon. 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 CreateRegularPolygonalFloorWithRegularPolygonalOpening(Document doc, Level level, XYZ location, XYZ normal, double floorradius, int floorsides, double openingradius, int openingsides)
    {
        CurveArray profile = new CurveArray();
        for (int i = 0; i < floorsides; i++)
        {
            double curAngle = i * Math.PI / floorsides * 2;
            double nextAngle = (i < floorsides - 1 ? i + 1 : 0) * Math.PI / floorsides * 2;

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

            profile.Append(line);
        }

        Floor floor = doc.Create.NewFloor(profile, false);
        doc.Regenerate();

        CurveArray profile1 = new CurveArray();
        for (int i = 0; i < openingsides; i++)
        {
            double curAngle = i * Math.PI / openingsides * 2;
            double nextAngle = (i < openingsides - 1 ? i + 1 : 0) * Math.PI / openingsides * 2;

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

            profile1.Append(line);
        }

        doc.Create.NewOpening(floor, profile1, false);

        return floor;
    }

Here is some sample caller code:

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

                    tran.Commit();
                }

Here is such a polygonal floor with a polygonal opening inside in Revit.
 PolygonalFloorWithPolygonalOpening

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