Message 1 of 21
Creating A Roof Using Revit APIs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am facing an issue while creating a roof using C# Revit APIs.
I am automating the conversion of 2D AutoCAD drawings to Revit 3D models. The process involves reading data from AutoCAD drawings. I store the polylines (on which I want to create the roof) in a list, specifically List<PolyLine> roofPolyLineList, and pass it to my function. First, I convert the polyline into a CurveArray, CurveArray topFloorCurveArray = application.Create.NewCurveArray(), and pass it to the API. I am not getting any errors, but the roof is not created in Revit.
I have attached my code below.
Please help me to solve the issue.
private void CreateRoof(Document doc, List<Level> floorlevels, List<PolyLine> roofPolyLineList)
{
Application application = doc.Application;
CurveArray topFloorCurveArray = application.Create.NewCurveArray();
RoofType roofType= new FilteredElementCollector(doc).OfClass(typeof(RoofType)).FirstOrDefault<Element>() as RoofType;
Transaction trans = new Transaction(doc, "Create Roof");
trans.Start();
{
for (int i = 0; i < roofPolyLineList.Count; ++i)
{
var points = roofPolyLineList[i].GetCoordinates();
for (int j = 0; j < points.Count - 1; j++)
{
var start = points[j];
var end = points[j + 1];
var line = Line.CreateBound(new XYZ(start.X, start.Y, start.Z), new XYZ(end.X, end.Y, end.Z));
topFloorCurveArray.Append(line);
}
}
for (int i = 0; i < floorlevels.Count; i++)
{
int count = floorlevels.Count;
string name = "Floor " + (count - 1);
Level level = floorlevels[i];
if (level.Name == name)
{
ModelCurveArray footPrintToModelCurveMapping = new ModelCurveArray();
FootPrintRoof footprintRoof = doc.Create.NewFootPrintRoof(topFloorCurveArray, 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);
}
}
}
doc.Regenerate();
trans.Commit();
}
}

Developer Advocacy and Support +