0

I'm trying to create the roof as shown in below image using the revit api. Selected roof is placed at Offset From Roof Base at 10' 1" and Adjacent roof is placed at 9'1".

enter image description here

But using the revit api I'm getting this as output. Current Output

Please let us know how we can create above roof using revit api

We are using only the model lines from revit document as shown below enter image description here

1 Answers1

0

What exact existing elements and detailed steps are you using to create that roof manually in the end user interface? You will probably need to use the same starting point to create the roof programmatically as well. In general, the Revit API just wraps the manual UI functionality.

Creating the roof with the existing elements and their slope settings should be pretty straightforward using the NewFootPrintRoof method. Look at the sample code snippet in the documentation:

// 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.OfClass(typeof(Level));
var elements = from element in collector where element.Name == "Roof" select element;
Level level = elements.Cast<Level>().ElementAt<Level>(0);

collector = new FilteredElementCollector(document);
collector.OfClass(typeof(RoofType));
RoofType roofType = collector.FirstElement() as RoofType; 

// 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);
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
if (selectedIds.Count != 0)
{
  foreach (ElementId id in selectedIds)
  {
    Element element = document.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("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);
}
Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Manually we only take the model lines from the user and after we follow below steps. Steps we follow for roof creation. 1) We create roof using the revit api by providing the roof details to line. 2) We read the top faces of the roof and extract roof lines for each side of the roof. 3) We use the same roof lines and create the roof again for each side seperately using the api. – Veeresh Huvinahalli Jun 22 '23 at 05:00
  • I have modified the original question by adding the model lines we are using for roof creation. Please let me know if you need more details on it. – Veeresh Huvinahalli Jun 22 '23 at 05:47
  • I see the closed loop of model lines. Are they all in the same height? Why does the target roof extend down different distances on different sides? Surely you must be specifying additional settings to achieve that effect? – Jeremy Tammik Jun 23 '23 at 08:27
  • All the line are same height except one? I'm attaching the screenshot of model lines with slope and plate height used while creating the roof. – Veeresh Huvinahalli Jun 23 '23 at 09:26