Creating A Roof Using Revit APIs

Creating A Roof Using Revit APIs

aniket_pachore
Enthusiast Enthusiast
1,684 Views
20 Replies
Message 1 of 21

Creating A Roof Using Revit APIs

aniket_pachore
Enthusiast
Enthusiast

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();
            }
        }

 

0 Likes
1,685 Views
20 Replies
Replies (20)
Message 21 of 21

scgq425
Advocate
Advocate

Hi @aniket_pachore :

i was has a seem problem , when i place a base-face-family use api , run succeed and not visable or move it will visable  ,the result  is a old version bug , u can update  revit version and try again .

i dont konw u revit version ,so  if a old version , can try this .

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes