CreateFromRebarShape Method


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. 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.

Namespace: Autodesk.Revit.DB.Structure
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:  2009

Syntax

C#
public static Rebar CreateFromRebarShape(
	Document doc,
	RebarShape rebarShape,
	RebarBarType barType,
	Element host,
	XYZ origin,
	XYZ xVec,
	XYZ yVec
)
Visual Basic
Public Shared Function CreateFromRebarShape ( _
	doc As Document, _
	rebarShape As RebarShape, _
	barType As RebarBarType, _
	host As Element, _
	origin As XYZ, _
	xVec As XYZ, _
	yVec As XYZ _
) As Rebar
Visual C++
public:
static Rebar^ CreateFromRebarShape(
	Document^ doc, 
	RebarShape^ rebarShape, 
	RebarBarType^ barType, 
	Element^ host, 
	XYZ^ origin, 
	XYZ^ xVec, 
	XYZ^ yVec
)

Parameters

doc
Type: Autodesk.Revit.DBDocument
A document.
rebarShape
Type: Autodesk.Revit.DB.StructureRebarShape
A RebarShape element that defines the shape of the rebar.
barType
Type: Autodesk.Revit.DB.StructureRebarBarType
A RebarBarType element that defines bar diameter, bend radius and material of the rebar.
host
Type: Autodesk.Revit.DBElement
The element to which the rebar belongs. The element must support rebar hosting; [!:Autodesk::Revit::DB::Structure::RebarHostData].
origin
Type: Autodesk.Revit.DBXYZ
The lower-left corner of the shape's bounding box will be placed at this point in the project.
xVec
Type: Autodesk.Revit.DBXYZ
The x-axis in the shape definition will be mapped to this direction in the project.
yVec
Type: Autodesk.Revit.DBXYZ
The y-axis in the shape definition will be mapped to this direction in the project.

Return Value

The newly created Rebar instance, or a null reference (Nothing in Visual Basic) if the operation fails.

Examples

CopyC#
// 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;
}
CopyVB.NET
' Create 2 adjacent rebars with the given RebarShape and RebarBarType
Private Function CreateRebar(doc As Document, wall As Wall, barShape As RebarShape, barType As RebarBarType) As List(Of Rebar)
    Dim newRebars As New List(Of Rebar)()

    Dim bar As Rebar = 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
    Dim barLength As Double = 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
End Function

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentException The element host was not found in the given document. -or- host is not a valid rebar host.
Autodesk.Revit.ExceptionsArgumentNullException A non-optional argument was null
Autodesk.Revit.ExceptionsArgumentOutOfRangeException xVec has zero length. -or- yVec has zero length.

See Also