Search code examples
c#revit-apirevit

Control the laid out area of rebar set


I am using Revit API to create a set of rebar for a beam. By default, when I change the layout rule (using Revit API as well as end user UI), no matter where I place my rebars, they will automatically adjust to spread out the entire face of the host (in this case, the top face of the beam).

However, I want to control the area that my rebars will be laid out so that they only cover a small part but not the entire face of the host when I change rebar layout rule (using Revit API). If I using the end user UI, I can manually grab the handle at the edge of rebar set then adjust the laid out-area after changing layout rule.

I intend to switch from "single" rule (default) to "fixed number" rule. How can I do this? In the worst scenario, I can use "single" rule and place each of the rebar at the desire place, though.


Solution

  • The development team already answered your question in the Revit API discussion forum thread on controlling the laid out area of rebar set:

    There is a difference between how the layout rule is changed from API or from UI. I’ll explain how it works from API for a Shape Driven Rebar.

    We have a Rebar element. We obtain the RebarShapeDrivenAccessor and we will work with this class. There is a property called Normal. It represent the normal of the plane on which the rebar is bent. Also, based on this vector it will decide in which direction will expand the set.

    The function

    public void SetLayoutAsFixedNumber( int numberOfBarPositions, double arrayLength, bool barsOnNormalSide, bool includeFirstBar, bool includeLastBar);

    has the following parameters:

    • numberOfBarPositions - How many bars are in the set
    • arrayLength – How long is the set - the distance between the first bar and the last bar in the set
    • barsOnNormalSide - In which part will go the set, in the direction of the normal or opposite
    • includeFirstBar - True if the first bar in set should be visible, false otherwise
    • includeLastBar - True if the last bar in set should be visible, false otherwise

    So, when will change layout from single to any other layout the bar that you see on screen it will keep its position and will be the first bar in the set. It will calculate where is the last bar in the set according to the arrayLength and barsOnNormalSide and will distribute the bars between these two.

    In order to obtain the result you can set layout with the array length equal with your zone length (the set will start from the existing bar on the screen) and then you can move the Rebar element where you want.

    Or, you can move the single bar where zone starts and then set layout with array length equal with your zone length.