Above is my first functional C# revit add-in, making bending rebar at any angle an easy task. For those non-structural engineers, the smaller the piece of rebar, the smaller the allowable bend. Being able to quickly sketch rebar to scale with minimum bend radii is often helpful to see if a detail sketch is constructible. This add-in will bend rebar to the ACI minimum allowable bend diameter and will allow for as many points as the user desires.

How to use the add-in

To start the add-in navigate to the add-in tab, click the drop down and select your desired rebar size. Once clicked, you can now start clicking the points where you want to draw the rebar. Once you are done selecting your rebar points (3) minimum, you hit escape to have Revit create a filled region in the location where you clicked. Currently, the filled region defaults to a filled region type of "Solid Black", make sure you have this filled region in your revit project for the add-in to work. The code was written for Revit 2022, I have yet to try the code in any other version of revit.

You can find the code on my github.

Lessons Learned in C#

Given that this was my first real dive in C# and the Revit API, there were a ton of things to learn a few examples.

  • 2/12 does not equal what you think it might, you have to cast your integer 2 and integer 12 to a double as shown below


        double x = 2/12; //This actually = 0
        double x = (double)2/(double)12; // 0.16667


  • I still do not fully understand FilteredElementCollector (this class gathers revit items from my understanding). Looking at these lines of code is intimidating... The lines below gather all of the filled region types in the revit project and finds the unique ID for "Solid Black"

 // find solid fill type in our revit list
            FilteredElementCollector fillRegionTypes = new FilteredElementCollector(doc).OfClass(typeof(FilledRegionType));
            var patterns = new FilteredElementCollector(doc).OfClass(typeof(FilledRegionType)).FirstElement();
            foreach (Element elem in fillRegionTypes)
                if (elem.Name == "Solid Black")
                    patterns = elem;

  • I made a fun function that tests if user selected points are clicked in clockwise or counterclockwise manner. I was super proud of this, then found out that the Revit API has this function prebuilt into the Curveloop class. I am going to tell myself that my function is way more optimized than the curveloop method to make myself feel better.

public static double ClockWise(List<XYZ> pnts)
            double y = 0;
            for (int i = 0; i <= pnts.Count - 1; i++)
                if (i == pnts.Count - 1)
                    double x = (pnts[0].X - pnts[i].X) * (pnts[0].Y + pnts[i].Y);
                    y = (double)y + (double)x;
                    double x = (pnts[i + 1].X - pnts[i].X) * (pnts[i + 1].Y + pnts[i].Y);
                    y = (double)y + (double)x;
            bool CW_CCW = true;
            if (y <= (double)0)
                CW_CCW = false;
            return y;

Future Work

Currently this add-in will not work in any view other than a drafting view, I would like to come back to this at some point and let the code work in live view. I should have tested this earlier, I started into this task trying to alleviate the issues of the original revit rebar bender and keep this completely detail component based. 

Another item to add in the future is to load the predefined hooked ends, e.g. 90 135, 180 degree hooks. This should be pretty easy if I am thinking about this correctly, but might the necessitate the need for popup window for the user to select hook end directions and hook types

More items off the top of my head, allow for self intersection (currently breaks if the rebar loops cross), update the sloppy code up on Github (could probably be 300 lines instead of 900 lines), learn C# better. Currently I do not know how to have a function return multiple outputs like a list and int. Overall a fun project that yields a semi functional end product, I will never complain about that.

Download the code off of github and try it out, let me know if you have any comments.


Revit C Sharp


For the 2/12 issue, try 2/12.0 or 2.0/12.0. Older version of Python division operator used to behave in a similar way but adding a x.0 forced a number to be considered a float instead.

Thanks Celt, 2.0/12.0 does work. Good to know.

Our Sidebar

You can put any information here you'd like.

  • Latest Comments
  • Liz_Larsen on R2R - Update V1.1.0 -

    Great job! We've been wanting a tool like this for so long that I'd considered making it myself. During my research, I stumbled across this blog right around the time you were looking for testers a few months ago. 

    I'll be sure to spread the word about this amazing tool. Thanks …

  • retug on ETABs API - More Examples (Database Tables) -

    Hi rajavardhan, are you not able to delete selected frames and walls based on section properties through the ETABs program itself? Or through the API? I could put together a few quick examples for you with the API if needed.

  • rajavardhan on ETABs API - More Examples (Database Tables) -

    Hi, I am not able to select frames and walls based on section properties in etabs v21 and then delete selected frames and walls..can anyone suggest me the code to do it use Excel VBA code