Rebar

The Rebar class represents rebar used to reinforce suitable elements, such as concrete beams, columns, slabs or foundations.

Creating rebar

You can create rebar objects using one of three static Rebar methods.

Name

Description

public static Rebar Rebar.CreateFromCurves(
        Document doc,
        RebarStyle style,
        RebarBarType rebarType,
        RebarHookType startHook,
        RebarHookType endHook,
        Element host,
        XYZ norm,
        IList<Curve> curves,
        RebarHookOrientation startHookOrient,
        RebarHookOrientation endHookOrient,
        bool useExistingShapeIfPossible,
        bool createNewShape
);

Creates a new instance of a Rebar element within the project. All curves must belong to the plane defined by the normal and origin.

public static Rebar Rebar.CreateFromRebarShape(
        Document doc,
        RebarShape rebarShape,
        RebarBarType rebarType,
        Element host,
        XYZ origin,
        XYZ xVec,
        XYZ yVec
);

Creates a new Rebar, as an instance of a RebarShape. The instance will have the default shape parameters from the RebarShape, and its location is based on the bounding box of the shape in the shape definition. Hooks are removed from the shape before computing its bounding box. If appropriate hooks can be found in the document, they will be assigned arbitrarily.

public static Rebar Rebar.CreateFromCurvesAndShape(
        Document doc,
        RebarShape rebarShape,
        RebarBarType rebarType,
        RebarHookType startHook,
        RebarHookType endHook,  
        Element host,
        XYZ norm,
        IList<Curve> curves,
        RebarHookOrientation startHookOrient,
        RebarHookOrientation endHookOrient
);
Creates a new instance of a Rebar element within the project. The instance will have the default shape parameters from the RebarShape. All curves must belong to the plane defined by the normal and origin.

The first version creates rebar from an array of curves describing the rebar, while the second creates a Rebar object based on a RebarShape and position. The third version creates rebar from an array of curves and based on a RebarShape.

When using the CreateFromCurves() or CreateFromCurvesAndShape() method, the parameters RebarBarType and RebarHookType are available in the RebarBarTypes and RebarHookTypes properties of the Document.

The following code illustrates how to create Rebar with a specific layout.

Code Region 29-8: Creating rebar with a specific layout

Rebar CreateRebar(Autodesk.Revit.DB.Document document, FamilyInstance column, RebarBarType barType, RebarHookType hookType)
{
    // Define the rebar geometry information - Line rebar
    LocationPoint location = column.Location as LocationPoint;
    XYZ origin = location.Point;
    XYZ normal = new XYZ(1, 0, 0);
    // create rebar 9' long
    XYZ rebarLineEnd = new XYZ(origin.X, origin.Y, origin.Z + 9);
    Line rebarLine = Line.CreateBound(origin, rebarLineEnd);

    // Create the line rebar
    IList<Curve> curves = new List<Curve>();
    curves.Add(rebarLine);

    Rebar rebar = Rebar.CreateFromCurves(document, Autodesk.Revit.DB.Structure.RebarStyle.Standard, barType, hookType, hookType,
                        column, origin, curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, true);

    if (null != rebar)
    {
        // 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
        rebar.SetLayoutAsFixedNumber(10, 1.5, true, true, true);
    }

    return rebar;
}
Note: For more examples of creating rebar elements, see the Reinforcement and NewRebar sample applications included with the Revit SDK.

The following table lists the integer value for the Parameter REBAR_ELEM_LAYOUT_RULE:

Table 59: Rebar Layout Rule

Value

0

1

2

3

4

Description

None

Fixed Number

Maximum Spacing

Number with Spacing

Minimum Clear Spacing

The Rebar.ScaleToBox() method provides a way to simultaneously set all the shape parameters. The behavior is similar to the UI for placing Rebar.

RebarHostData and RebarCoverType

Clear cover is associated with individual faces of valid rebar hosts. You can access the cover settings of a host through the Autodesk.Revit.Elements.RebarHostData object. A simpler, less powerful mechanism for accessing the same settings is provided through parameters.

Cover is defined by a named offset distance, modeled as an element Autodesk.Revit.DB.Structure.RebarCoverType.

Numbering

Rebar 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 rebar 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. Rebar) belonging to a particular schema (e.g. NumberingSchemaTypes.StructuralNumberingSchemas.Rebar) 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.

Elements get assigned to sequences either upon their creation (based on the then current numbering partition value), by explicitly modifying the Partition parameter of an element, or by using the AssignElementsToSequence() method. The AssignElementsToSequence() method is preferred over explicitly changing the Partition parameter, because the method applies changes to sequences and element numbers immediately, while changed parameters only go into effect after the current transaction is closed.

In addition to directly or indirectly changing the Partition parameter of elements, numbering sequences can be reorganized by using methods of the NumberingSchema class. The MoveSequence() method moves all elements of an existing sequence to a new sequence that does not exist yet in the schema, thus effectively renaming the Partition parameter on all the affected elements. The AppendSequence() method removes all elements from one sequence and appends them to elements of another existing sequence while applying the matching policy. The method MergeSequences() takes elements of all specified sequences and moves them all into a newly created sequence. All the merged elements will be renumbered and matched as needed based on the matching algorithm.

The sample below uses the MoveSequence() method to swap numbers for Rebar in two numbering sequences.

Code Region: Swap numbers
/// <summary>
/// This method uses multiple moving operations to swap numbers
/// for Rebars in two numbering sequences. The sequences are
/// identified by the names of two numbering partitions.
/// </summary>
/// <param name="document">Document to modify</param>
/// <param name="part1">Name of the partition of one numbering sequence</param>
/// <param name="part2">Name of the partition of another numbering sequence</param>
private void SwapNumberingSequences(Document document, string part1, string part2)
{
    // Obtain a schema object for a particular kind of elements 
    NumberingSchema schema = NumberingSchema.GetNumberingSchema(document,NumberingSchemaTypes.StructuralNumberingSchemas.Rebar);

    using (Transaction transaction = new Transaction(document))
    {
        // Changes to numbering sequences must be made inside a transaction
        transaction.Start("Swap Numbering Sequences");

        // We will use a temporary partition for the swap operation,
        // for the move operation only works if the target partition 
        // does not exist yet in the same numbering schema.
        // (We assume this TEMPORARY partition does not exist.)
        string tempPartition = "TEMPORARY";

        // Step 1
        // First we move all elements from one sequence into 
        // a partition we know does not exist. This action will
        // create the temporary partition and remove the original
        // one (part1).
        schema.MoveSequence(part1, tempPartition);

        // Step 2
        // With the sequence in partition 'part1' removed
        // we can now move elements from the second sequence to it.
        // This action will re-create a sequence in partition 'part1'
        // and remove the sequence in partition 'part2'
        schema.MoveSequence(part2, part1);

        // Step 3
        // Finally, we can move elements 'parked' in the temporary
        // sequence to partition 'part2', for that partition was
        // removed in the previous step and thus can now be created
        // again. The temporary partition will be automatically 
        // removed upon completing this step.
        schema.MoveSequence(tempPartition, part2);

        transaction.Commit();
    }
}

Elements in different sequences are numbered independently, meaning that there may be elements with the same number in two sequences even though the elements are different. Likewise, there may be perfectly identical elements in two or more sequences bearing different numbers. However, within each one numbering sequence any two identical elements will always have the same number, while different elements will never have the same number within a numbering sequence.

Enumerable elements are always numbered automatically upon their creation. Each new element will get an incrementally higher number. However, new elements that match existing elements within the same sequence will get the same number assigned. Elements will keep their assigned numbers as long as it is possible. This means, for example, that if some previously created rebar elements get deleted, all remaining elements (within the same numbering sequence) will keep their numbers, which may result in gaps in the respective numbering sequence. Gaps can be removed by invoking RemoveGaps() for sequences in which gaps are not desired.

The following example consolidates the numbers on Rebar elements by removing any remaining gaps in numbering sequences and setting the start number of each sequence so numbers in sequences do not overlap.

Code Region: Consolidate Rebar numbers
private void ConsolidateRebarNumbers(Document document)
{
    // Obtain a schema object for a particular kind of elements 
    NumberingSchema schema = NumberingSchema.GetNumberingSchema(document,NumberingSchemaTypes.StructuralNumberingSchemas.Rebar);

    // Collect the names of partitions of all the numbering sequences currently contained in the schema
    IList<string> sequences = schema.GetNumberingSequences();

    using (Transaction transaction = new Transaction(document))
    {
        // Changes to numbers must be made inside a transaction
        transaction.Start("Consolidate Rebar Numbers");

        // First we make sure numbers in all sequences are consecutive
        // by removing possible gaps in numbers. Note: RemoveGaps does
        // nothing for a sequence where there are no gaps present.

        // We also want to find what the maximum range of numbers is
        // of all the sequences (the one the widest span of used numbers)
        int maxRange = 0;

        foreach (string name in sequences)
        {
            schema.RemoveGaps(name);

            // Here we use First() from the Linq extension.
            // There is always at least one range in every sequence,
            // and after gaps are closed there is exactly one range.
            IntegerRange range = schema.GetNumbers(name).First();  
            int rangeSpan = 1 + (range.High - range.Low);
            if (rangeSpan > maxRange)
            {
                maxRange = rangeSpan;
            }
        }

        // Next we give sequences different start numbers
        // starting with 100 and then stepping by at least
        // the maximum range we found in the previous step
        int startNumber = 100;

        // We round the range up to the closest 100
        int step = 100 * (int)((maxRange + 99) / 100.0);

        foreach (string name in sequences)
        {
            schema.ShiftNumbers(name, startNumber);
            startNumber += step;
        }

        transaction.Commit();
    }
}

Numbers are stored as values of a numbering parameter on each numbered element. The Id of the parameter is obtained by querying the NumberingSchema.NumberingParameterId property. The value of the number can be obtained by querying the parameter for the respective numbered element. The value is read-only and thus cannot be set; it is always computed based on relations of elements across numbering partitions and the matching policy within the numbering sequence of each element.

Even though numbers are always assigned automatically to all elements of a schema, the method ChangeNumber() gives the programmer a way to explicitly overwrite a specific number as long as the new number is unique in the numbering sequence. The caller specifies a number to be changed and a new value that is to be applied, providing the value does not exist yet in the same numbering sequence.