Rebar Couplers

Rebar couplers are used to connect adjacent rebar.

Creating couplers

Couplers can connect two adjacent rebar or cap the end of a single rebar. Couplers are represented by the RebarCoupler class. The static Create() method can be used to create new couplers.

The following example creates a coupler to connect two adjacent single rebar bars. The Create() method needs the ElementId of a coupler type and the RebarReinforcementData for the two rebars to connect.

Code Region: Creating a rebar coupler

private RebarCoupler CreateCoupler(Document doc, List<Rebar> bars)
{
    RebarCoupler coupler = null;
    // if we have at least 2 bars, create a coupler between them
    if (bars.Count > 1)
    {
        // get a type id for the Coupler
        ElementId defaultTypeId = doc.GetDefaultFamilyTypeId(new ElementId(BuiltInCategory.OST_Coupler));

        if (defaultTypeId != ElementId.InvalidElementId)
        {
            // Specify the rebar and ends to couple
            RebarReinforcementData rebarData1 = RebarReinforcementData.Create(bars[0].Id, 0);
            RebarReinforcementData rebarData2 = RebarReinforcementData.Create(bars[1].Id, 1);

            RebarCouplerError error;
            coupler = RebarCoupler.Create(doc, defaultTypeId, rebarData1, rebarData2, out error);
            if (error != RebarCouplerError.ValidationSuccessfuly)
            {
                TaskDialog.Show("Revit", "Create Coupler failed: " + error.ToString());
            }

            // Use a coupler to cap the other end of the first bar
            RebarReinforcementData rebarData = RebarReinforcementData.Create(bars[0].Id, 1);
            RebarCoupler.Create(doc, defaultTypeId, rebarData, null, out error);
            if (error != RebarCouplerError.ValidationSuccessfuly)
            {
                TaskDialog.Show("Revit", "Create Coupler failed: " + error.ToString());
            }
        }
    }

    return coupler;
}

If the coupler cannot be created, a RebarCouplerError enum will be returned. Some reasons the creation may fail include bars not touching, different layouts between the rebar sets, or the bars may be the wrong diameter for the coupler.

The CouplerLinkTwoBars() method will return true if the coupler connects two rebars, or false it if only caps one rebar.

The Rebar class has a GetCouplerId() method to get the id of the a coupler attached to either end of the rebar.

Coupler location

To get the location point or points (in the case of a rebar set), call the GetPointsForPlacement() method, which returns a list of XYZ points indicating where the coupler (or couplers) are placed. The GetCouplerPositionTransform() method will return a transform representing the relative position of the coupler at a specified index in the set. The index should be between 0 and the coupler quantity - 1. GetCouplerQuantity() will return the quantity of couplers in the set.

Numbering

RebarCoupler is one of the categories of elements whose numbering can be controlled via the Revit API. The NumberingSchema and NumberingSchemaType classes can be used to define how coupler elements are to be organized for the purpose of numbering/tagging them. Each NumberingSchema controls numbering of elements of one particular kind. Instances of NumberingSchema are also elements and there is always only one of each type in every Revit document. Available types of all built-in numbering schemas are enumerated in NumberingSchemaTypes class.

Elements (e.g.RebarCoupler) belonging to a particular schema (e.g. NumberingSchemaTypes.StructuralNumberingSchemas.RebarCoupler) are organized and numbered in sequences. A sequence is a collection of elements that share the same numbering partition as defined by their respective values of the Partition parameter (NUMBER_PARTITION_PARAM). A numbering sequence must contain at least one element. In other words, a sequence is established once there is at least one element of which the partition parameter has a value that differs from other elements (in the same numbering schema). If the last element is removed (deleted or moved to a different sequence) then the empty sequence ceases to exist.

End Treatments

The end treatment for a rebar bar comes from the coupler attached to it. The end treatment type for both ends of the coupler is specified by the coupler family type.

The overloaded EndTreatmentType.Create() method can be used to create a new EndTreatmentType with or without a string to specify the end treatment name. The CreateDefaultEndTreatmentType() method creates a new EndTreatmentType with a default name.

To access the end treatment type for a RebarCoupler, use the BuiltInParameters COUPLER_MAIN_ENDTREATMENT to set End Treatment 1 and COUPLER_COUPLED_ENDTREATMENT to set End Treatment 2 for the FamilySymbol representing the rebar coupler type. The example below creates a new EndTreatmentType and assigns it to End Treatment 1 for the coupler type. An existing EndTreatmentType can also be used.

Code Region: Change EndTreatmentType for RebarCoupler

private void NewEndTreatmentForCouplerType(Document doc, ElementId couplerTypeId)
{
    EndTreatmentType treatmentType = EndTreatmentType.Create(doc, "Custom");
    FamilySymbol couplerType = doc.GetElement(couplerTypeId) as FamilySymbol;
    Parameter param = couplerType.get_Parameter(BuiltInParameter.COUPLER_MAIN_ENDTREATMENT);
    param.Set(treatmentType.Id);
}

An end treatment can be defined in a RebarShape to define the shapes that have specific treatments at the ends. The end treatment in the RebarShape is used for shape recognition. The user defines the shapes according to their specifications and when a coupler is placed on a bar, it automatically searches for the right RebarShape, if the ReinforcementSettings.RebarShapeDefinesEndTreatments property is set to true. Note that this property can only be set before any rebar or reinforcement are added to the document.

Code Region: Set and EndTreatmentType for a RebarShape

private bool SetEndTreatmentType(Document doc, RebarShape rebarShape)
{
    bool set = false;
    // check if end treatments are defined by rebar shape
    ReinforcementSettings settings = ReinforcementSettings.GetReinforcementSettings(doc);
    if (!settings.RebarShapeDefinesEndTreatments)
    {
        try
        {
            // can only be changed if document contains no rebars, area reinforcement or path reinforcement
            settings.RebarShapeDefinesEndTreatments = true;
        }
        catch (Exception e)
        {
            // cannot change the settings value
            TaskDialog.Show("Revit", e.Message);
        }
    }
    if (settings.RebarShapeDefinesEndTreatments)
    {
        EndTreatmentType treatmentType = EndTreatmentType.Create(doc, "Flame Cut");
        rebarShape.SetEndTreatmentTypeId(treatmentType.Id, 0);

        ElementId treatmentTypeId = EndTreatmentType.CreateDefaultEndTreatmentType(doc);
        rebarShape.SetEndTreatmentTypeId(treatmentTypeId, 1);

        set = true;
    }

    return set;
}

The RebarShape class has methods to determine if it has end treatments, and methods to get and set the EndTreatmentType for both ends of the RebarShape.

Note that the following methods require that the RebarShape have no end treatments:

  • RebarContainer.AppendItemFromRebar()
  • RebarContainer.AppendItemFromRebarShape()
  • RebarContainer.AppendItemFromCurvesAndShape()
  • RebarContainerItem.SetFromRebar()
  • RebarContainerItem.SetFromRebarShape()
  • RebarContainerItem.SetFromCurvesAndShape()
  • RebarContainerItem.RebarShapeId

Additionally, the Rebar class as a method to get the end treatment id of any end treatment applied to the rebar ends. The end treatments are based on an attached coupler, so a Rebar will not contain an EndTreatmentTypeId for an end that is not attached to a coupler.

Code Region: Get end treatments for Rebar

private void ListEndTreatments(Document doc, List<Rebar> bars)
{
    StringBuilder info = new StringBuilder();
    for (int n = 0; n < bars.Count; n++)
    {
        // get end treatment for both ends of bar
        for (int i = 0; i < 2; i++)
        {
            ElementId treatmentTypeId = bars[n].GetEndTreatmentTypeId(i);
            if (treatmentTypeId != ElementId.InvalidElementId)
            {
                EndTreatmentType treatmentType = doc.GetElement(treatmentTypeId) as EndTreatmentType;
                info.AppendLine(string.Format("End treatment for bar {0} end {1}: {2}", n, i, treatmentType.EndTreatment));
            }
        }
    }

    TaskDialog.Show("Revit", info.ToString());
}