Rebar Containers

Rebar Containers are elements which represent an aggregation of rebars in one host. This element can only be created via the API.

The advantages of using the RebarContainer element are:

Each RebarContainer contains a collection (empty when first created) of RebarContainerItem objects. RebarContainerItem provides properties and methods similar to that of a Rebar element.

Creating a new RebarContainer

You may use the static method RebarContainer.Create() which requires the Document in which you want to create a new RebarContainer, the host Element which will host the new RebarContainer and the ElementId of the RebarContainerType which will be assigned to the new RebarContainer.

Filling a RebarContainer

Once you have a new RebarContainer object, you can fill it up with RebarContainerItems by calling one of the following methods on the RebarContainer object:

  • AppendItemFromRebar() - Appends a RebarContainerItem to the collection using properties of the Rebar element used to create it.
  • AppendItemFromCurves() - Appends a RebarContainerItem to the collection from a list of curves using properties from the specified RebarBarType.
  • AppendItemFromRebarShape() - Appends a RebarContainerItem to the collection using properties from the specified RebarBarType and RebarShapeType.
  • AppendItemFromCurvesAndShape() - Appends a RebarContainerItem to the collection from a list of curves using properties from the specified RebarBarType and RebarShapeType.

Note that in creating the container items, you will often be required to specify the normal of the plane in which the curves exist. This normal also defines the direction of multiple rebar creation if you set the layout rules to anything other than single. If you set the RebarContainerItem to a FixedNumber layout rule, for instance, those additional bars will be distributed along a line perpendicular to the plane you specify when creating the RebarContainerItem. In this sense the Normal also serves as the direction of distribution for RebarContainerItems with layout rules applied.

Code Region: Creating a rebar container

void AddItemsToRebarContainer(RebarContainer container, FamilyInstance beam, RebarBarType barType, RebarHookType hookType)
{
    // Define the rebar geometry information - Line rebar
    LocationCurve location = beam.Location as LocationCurve;
    XYZ origin = location.Curve.GetEndPoint(0);
    // create rebar along the length of the beam
    XYZ rebarLineEnd = location.Curve.GetEndPoint(1);
    Line line = Line.CreateBound(origin, rebarLineEnd);
    XYZ normal = new XYZ(1, 0, 0);
    Curve rebarLine = line.CreateOffset(0.5, normal);

    // Create the line rebar
    IList<Curve> curves = new List<Curve>();
    curves.Add(rebarLine);
            
    RebarContainerItem item = container.AppendItemFromCurves(RebarStyle.Standard, barType, hookType, hookType, normal, curves, RebarHookOrientation.Right, RebarHookOrientation.Left,
                                                                true, true);

    if (null != item)
    {
        // set specific layout for new rebar as fixed number, with 10 bars, distribution path length of 1.5'
        // with bars of the bar set on the same side of the rebar plane as indicated by normal
        // and both first and last bar in the set are shown
        item.SetLayoutAsFixedNumber(10, 1.5, true, true, true);
    }
}

Accessing RebarContainerItems

RebarContainer is derived from ICollection so its RebarContainerItems may be iterated as for any ICollection object.

Use the method RebarContainer.Contains() to query whether the particular RebarContainerItem exists in the RebarContainer.

RebarContainer provides methods to remove individual items, clear all items, get specific items and return the count of RebarContainerItems in the container.

RebarContainerType

Rebar Containers will have types. These types are agnostic to the individual RebarContainerItems contained in them but will afford access to the Container's parameters at the type level. It is a required argument for creation of a new RebarContainer. Obtain a default by calling the static method RebarContainerType.CreateDefaultRebarContainerType() to obtain the ElementId of a RebarContainerType if the desired one does not exist in the database.

RebarContainer parameters management

Because the RebarContainer may contain several different configurations of individual RebarContainerItems, the overall RebarContainer parameters will be derived from the contained RebarContainerItem members if possible. If the parameter exists on all RebarContainerItems and it is the same across all RebarContainerItems in the RebarContainer then the RebarContainer parameter will show this value. If they are different, or do not exist on all RebarContainerItems in the Container, the parameter will display without value.

To allow you to manage this and specify necessary parameters for the RebarContainer as a whole, you may request the RebarContainerParameterManager from the RebarContainer calling the method GetParametersManager() which will return an object you can use to override the parameters of the RebarContainer. As an example, TotalLength in a RebarContainer with multiple RebarContainerItems with differing lengths, will show an empty parameter for TotalLength. You can call the RebarContainerParametersManager method AddOverride() which has 4 overloads so that you can override the value of any of four value types of parameters (ElementId, Double, Integer, String). Use the method IsRebarContainerParameter() to determine if the parameter is a RebarContainer parameter before attempting to add an override for the parameter.

You can also add a shared parameter as an override to a RebarContainer by calling the method AddSharedParameterAsOverride() and passing in the id of the shared parameter. Check to see that the parameter has not already been added to the RebarContainer before calling this method.

You may remove overrides by calling the method RemoveOverride() or remove all overrides by calling ClearOverrides().

Individual overridden parameters may be set to be modifiable or read only by calling the methods SetOverriddenParameterModifiable() or SetOverriddenParameterReadonly() and query the same with the IsOverriddenParameterModifiable() method.

Lastly, to check if a RebarContainer parameter is overridden, call the method IsParameterOverridden() passing in the ElementId of the parameter in question.

Code Region: RebarContainer parameters management

// Override the value for A and set the parameter to modifiable for the given rebar container
void ManageParameters(RebarContainer container)
{
    RebarContainerParameterManager paramManager = container.GetParametersManager();

    Parameter aParam = container.LookupParameter("A");
    if (aParam != null)
    {
        paramManager.AddOverride(aParam.Id, 0.4);
        paramManager.SetOverriddenParameterModifiable(aParam.Id);
    }
}

RebarContainerItems

Rebar container items offer many of the same properties as do Rebar elements. They are a much lighter representation of a modeled rebar offering similar interactions in the UI but unlike the Rebar class which is derived from Element, RebarContainerItem is derived directly from System.Object.

You may redefine the RebarContainerItem represented by any RebarContainerItem by calling the class methods available on RebarContainerItem objects:

  • SetFromRebar()
  • SetFromCurves()
  • SetFromRebarShape()
  • SetFromCurvesAndShape()

These methods mimic the methods which were used on RebarContainer to create the RebarContainerItem in the first place and have identical or nearly identical arguments which can be used to modify any RebarContainerItem in the RebarContainer.

You may query the RebarBarType ID with the class property BarTypeId. In order to apply a different RebarBarType to the RebarContainerItem you must use the SetFrom methods on the RebarContainerItem (i.e. SetFromCurves() or SetFromRebar()).

You may also control the propagation direction of additional bars in the set by using the get/set class property BarsOnNormalSide