Roofs

Roofs

Roofs in the Revit Platform API all derive from the RoofBase object. There are two classes:

Both have a RoofType property that gets or sets the type of roof. This example shows how you can create a footprint roof based on some selected walls:

Code Region 11-3: Creating a footprint roof

// Before invoking this sample, select some walls to add a roof over.
// Make sure there is a level named "Roof" in the document.
 
// find the Roof level
FilteredElementCollector collector = new FilteredElementCollector(document);
collector.WherePasses(new ElementClassFilter(typeof(Level)));
var elements = from element in collector where element.Name == "Roof" select element;
Level level = elements.Cast<Level>().ElementAt<Level>(0);

RoofType rooftype = null;
// select the first rooftype
foreach (RoofType rt in document.RoofTypes)
{
        rooftype = rt;
        break;
}

// Get the handle of the application
Autodesk.Revit.ApplicationServices.Application application = document.Application;
 
// Define the footprint for the roof based on user selection
CurveArray footprint = application.Create.NewCurveArray();
UIDocument uidoc = new UIDocument(document);
if (uidoc.Selection.Elements.Size != 0)
{
        foreach (Autodesk.Revit.DB.Element element in uidoc.Selection.Elements)
        {
                Wall wall = element as Wall;
                if (wall != null)
                {
                        LocationCurve wallCurve = wall.Location as LocationCurve;
                        footprint.Append(wallCurve.Curve);
                        continue;
                }

                ModelCurve modelCurve = element as ModelCurve;
                if (modelCurve != null)
                {
                        footprint.Append(modelCurve.GeometryCurve);
                }
        }
}
else
{
        throw new Exception("You should select a curve loop, or a wall loop, or loops combination \nof walls and curves to create a footprint roof.");
}

ModelCurveArray footPrintToModelCurveMapping = new ModelCurveArray();
FootPrintRoof footprintRoof = document.Create.NewFootPrintRoof(footprint, level, rooftype, out footPrintToModelCurveMapping);
ModelCurveArrayIterator iterator = footPrintToModelCurveMapping.ForwardIterator();
iterator.Reset();
while (iterator.MoveNext())
{
        ModelCurve modelCurve = iterator.Current as ModelCurve;
        footprintRoof.set_DefinesSlope(modelCurve, true);
        footprintRoof.set_SlopeAngle(modelCurve, 0.5);
}

For an example of how to create an ExtrusionRoof, see the NewRoof sample application included with the Revit API SDK.

Gutter and Fascia

Gutter and Fascia elements are derived from the HostedSweep class, which represents a roof. They can be created, deleted or modified via the API. To create these elements, use one of the Document.Create.NewFascia() or Document.Create.NewGutter() overrides. For an example of how to create new gutters and fascia, see the NewHostedSweep application included in the SDK samples. Below is a code snippet showing you can modify a gutter element's properties.

Code Region 11-4: Modifying a gutter

public void ModifyGutter(Autodesk.Revit.DB.Document document)
{
        UIDocument uidoc = new UIDocument(document);
        ElementSet collection = uidoc.Selection.Elements;

        foreach (Autodesk.Revit.DB.Element elem in collection)
        {
                if (elem is Gutter)
                {
                        Gutter gutter = elem as Gutter;
                        // convert degrees to rads:
                        gutter.Angle = 45.00 * Math.PI / 180;
                        TaskDialog.Show("Revit","Changed gutter angle");
                }
        }
}