2021 Method
Changes 4
M

Rebar.CreateFromRebarShape

Description:
Creates a new shape driven 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.
public static Rebar CreateFromRebarShape(
	Document doc,
	RebarShape rebarShape,
	RebarBarType barType,
	Element host,
	XYZ origin,
	XYZ xVec,
	XYZ yVec
)
Return Value nullNothingnullptr The newly created Rebar instance, or null Nothing nullptr a null reference ( Nothing in Visual Basic) if the operation fails.
// Create 2 adjacent rebars with the given RebarShape and RebarBarType
private List<Rebar> CreateRebar(Document doc, Wall wall, RebarShape barShape, RebarBarType barType)
{
    List<Rebar> newRebars = new List<Rebar>();

    Rebar bar = Rebar.CreateFromRebarShape(doc, barShape, barType, wall, new XYZ(2, 0, 2), new XYZ(1, 0, 0), new XYZ(0, 0, 1));
    // call regenerate so that the TotalLength will be calculated before the transaction is committed
    doc.Regenerate();
    newRebars.Add(bar);

    // add a second bar adjacent to the first one
    double barLength = bar.TotalLength;
    bar = Rebar.CreateFromRebarShape(doc, barShape, barType, wall, new XYZ(2 + barLength, 0, 2), new XYZ(1, 0, 0), new XYZ(0, 0, 1));
    newRebars.Add(bar);

    return newRebars;
}