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 round roof. 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 IEnumerable<RoofType> FindRoofTypes(RvtDocument doc)
{
return new FilteredElementCollector(doc)
.WherePasses(new ElementClassFilter(typeof(RoofType), false))
.Cast<RoofType>();
}
public static RoofBase CreateRoundRoof(Document doc, Level level, RoofType rooftype,
XYZ location, XYZ normal, double radius,
double slopeangle, double offset)
{
CurveArray profile = new CurveArray();
Arc arc1 = doc.Application.Create.NewArc(new Plane(normal, location), radius, 0, Math.PI);
Arc arc2 = doc.Application.Create.NewArc(new Plane(normal, location), radius, Math.PI, 2 * Math.PI);
profile.Append(arc1);
profile.Append(arc2);
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.CreateRoundRoof(
CachedDoc,
RoofCreation.FindAndSortLevels(CachedDoc).First(),
RoofCreation.FindRoofTypes(CachedDoc).First(),
XYZ.Zero,
XYZ.BasisZ,
100,
Math.PI / 6,
0.0);
...
Here is such a round 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.