Set structural floor span direction using c#

I’m working on a C# script aimed at editing the profile of a structural floor element using profile generated from Rhino, a warning appears indicating “Structural floor span direction not specified” upon attempting to set the sketch profile to the floor element. can any one help?

Hi Ahmed,

It’s best to post full environment details as well as progress/example files, even then if its a pure API questions there are forums dedicated to the Revit API where you might get a quicker answer.

Here’s how you do it in Rhino.Inside.Revit

1 Like

Hi japhy,

Thanks for your kind and prompt response.

Actually this not my case, I’m attempting to set the span direction parameter while SketchEdit Mode is activated as the following screen Shoot

Here’s below the method that I’m using

    public static void updateRevitFloors(UIDocument uidoc, Document revitDoc, ForgeTypeId targetUnitConvertor, List<Area2> rhinoAreas)
    {


        FilteredElementCollector collector = new FilteredElementCollector(revitDoc);
        ICollection<Element> revitFloorElements = collector.OfClass(typeof(Floor)).ToElements();


        foreach (var rhinoArea in rhinoAreas)
        {
            Element FloorElment = revitFloorElements.FirstOrDefault(x => x.Id.ToString() == rhinoArea.ID);

            if (FloorElment != null)
            {



                Floor fl = FloorElment as Floor;



                Element sketchElement = revitDoc.GetElement(fl.SketchId);

                if (sketchElement != null)
                {

                    Sketch sketch = sketchElement as Sketch;

                    #region get old Profile Curves To be Removed

                    // Get sketch elements
                    var sketchEleIds = sketch.GetAllElements();

                    var oldProfileCurves = new List<ElementId>();
                    foreach (var i in sketchEleIds)
                    {

                        oldProfileCurves.Add(i);

                    }
                    #endregion


                    SketchEditScope sketchEditScope = new SketchEditScope(revitDoc, "Edit Sketch");
                    sketchEditScope.Start(sketch.Id);


                    using (Transaction transaction = new Transaction(revitDoc, "Modify sketch"))
                    {
                        transaction.Start();


                        // Delete curves from the current sketch
                        foreach (var curve in oldProfileCurves)
                        {
                          revitDoc.Delete(curve as ElementId);
                        }


                        List<Rhino.Geometry.Curve[]> crvList = new List<Rhino.Geometry.Curve[]>();

                        foreach (Curve i in rhinoArea.outerCurves)
                        {
                            crvList.Add(i.DuplicateSegments());

                        }


                        foreach (Curve i in rhinoArea.innerCurves)
                        {
                            crvList.Add(i.DuplicateSegments());


                        }
                        IEnumerable<Rhino.Geometry.Curve> flatCrvList = crvList.SelectMany(x => x);


                        foreach (var rhinoCrv in flatCrvList)
                        {
                            Autodesk.Revit.DB.Curve c = RhinoInside.Revit.Convert.Geometry.GeometryEncoder.ToCurve(rhinoCrv);
                            revitDoc.Create.NewModelCurve(c, sketch.SketchPlane);
                        }


                        fl.SpanDirectionAngle = 90 * Math.PI / 180;

                        transaction.Commit();
                    }

                    sketchEditScope.Commit(new RoomWarningSwallower());
                }
            }
        }

    }

Hi Ahmed,

I believe the same issue you are facing is still the same as if you are doing it with RiR instead of c# component. As you can see from the GIF below if you create a floor manually in revit api it will cause issues if the span direction is specified along one of the sketch/boundary edges instead of having the span direction defined with a separate line(which is the case when creating a floor using RiR).

RIR_FloorSpanDirection

1 Like

Lifesaver as usual. :smiley:. Thank you for your explanation. To move it step forward, here’s below a workaround to address this problem from my end:

I stored the existing span direction and then modified it to ensure that it did not align with any model line from the existing sketch profile. Subsequently, I safely removed the existing sketch profile, created the new sketch profile, and finally restored the span direction to its original value.

Something you can also do is to store the span direction parameter value > change the floor “Structural” parameter to false (it will become a normal floor and won’t cause errors if you remove the span direction from the sketch) > finish editing the sketch > change “Structural” parameter back to true > assign back the span direction parameter value.

This above workflow might be helpful, but keep in mind to avoid doing that if you are modeling rebar or have span direction symbols etc…

RIR_FloorSpanDirection2

2 Likes