In Revit .NET API 2013, though the NewWall method has been moved to the Wall class itself, the roof generation method has not. It is still in the Document.Create instance. Anyway, we figured where it is and were able to create some roofs.
In this article, let’s create a regular polygonal roof. Here is the core help method.
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;
}
Here is some sample caller code:
RoofCreation.CreateRegularPolygonalRoof(
CachedDoc,
RoofCreation.FindAndSortLevels(CachedDoc).First(),
RoofCreation.FindRoofTypes(CachedDoc).First(),
XYZ.Zero,
10.0,
8,
Math.PI / 6,
0.0);
Here is such a regular polygonal roof in Revit.
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.