Revit Answer Day and Creating a Roof

Today I'll just highlight two items that were also already pointed out by Jaime Rosales on the AEC DevBlog:

Revit Answer Day

Do you have any Revit or Revit LT questions that you’ve always wanted to get answered?

If so, please join the next instalment of Ask Autodesk Anything events, the Revit Answer Day on October 7, 2015.

This event is dedicated to answering your questions about Revit and Revit LT. We’ll have some DevTech engineers attending the event to answer your API questions. The event runs from 6 am to 6 pm Pacific Time and will take place in Autodesk Community. You can spend a minute, an hour, or the whole day in the Autodesk Community to interact directly with the folks who can answer every question about Revit you can think of.

Creating a Roof

This question was asked last week both on the Revit API discussion forum and Stack Overflow:

Question: I'm having trouble programmatically creating a roof. I know how to create a stairs, for example: I start a StairsEditScope, use CreateSketchedLanding with the right parameters to create my stairs and commit the StairsEditScope. I can't find a clue on how to create a roof from scratch, though. Any leads?

Answer: Please always search the Revit API help file RevitAPI.chm and the Revit online help before asking questions like this.

Here is the sample code provided by the latter, in the section on Roofs:

  // Before invoking this sample, select some walls 
  // to add a roof over. Make sure there is a level 
  // named "Roof" in the document.
 
  Level level
    = new FilteredElementCollector( doc )
      .OfClass( typeof( Level ) )
      .Where<Element>( e =>
        !string.IsNullOrEmpty( e.Name )
        && e.Name.Equals( "Roof" ) )
      .FirstOrDefault<Element>() as Level;
 
  RoofType roofType
    = new FilteredElementCollector( doc )
      .OfClass( typeof( RoofType ) )
      .FirstOrDefault<Element>() as RoofType;
 
  // Get the handle of the application
  Application application = doc.Application;
 
  // Define the footprint for the roof based on user selection
  CurveArray footprint = application.Create
    .NewCurveArray();
 
  UIDocument uidoc = new UIDocument( doc );
 
  ICollection<ElementId> selectedIds
    = uidoc.Selection.GetElementIds();
 
  if( selectedIds.Count != 0 )
  {
    foreach( ElementId id in selectedIds )
    {
      Element element = doc.GetElement( id );
      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(
      "Please select a curve loop, wall loop or "
      + "combination of walls and curves to "
      + "create a footprint roof." );
  }
 
  ModelCurveArray footPrintToModelCurveMapping
    = new ModelCurveArray();
 
  FootPrintRoof footprintRoof
    = doc.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 );
  }

To test it, please make sure you have some walls to hold up the roof and one of your levels is named Roof.

I just created a simple four-wall rectangle, selected them and ran the command.

This code creates a footprint roof.

Revit also provides other kinds.

It is important to understand the Revit product and the various roof types from an end user point of view before thinking about driving them programmatically.

The footprint roof created above is defined by a horizontal outline and is created using the Document.NewFootPrintRoof method. Such a roof can be flat, or you can specify a slope for each edge of the outline profile.

The Building Coder Xtra labs provides another working sample in the external command Lab2_0_CreateLittleHouse in Labs2.cs.

The Building Coder also provides these other roof-related posts:

Little house roof

Addendum – Setting FootPrintRoof Slope

For Kinjal and Carolina, to answer the Revit discussion forum thread on Creating a surface through the Revit API:

Here are all the discussions I found on this, before hitting the last and hopefully ultimate answer above that I already forgot I had written:

I hope this helps once and for all and I do not forget about this answer again.