Create Method


Automatically creates new railings with the specified railing type on all sides of a stairs or ramp element.

Namespace: Autodesk.Revit.DB.Architecture
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:  2013

Syntax

C#
public static ICollection<ElementId> Create(
	Document document,
	ElementId stairsOrRampId,
	ElementId railingTypeId,
	RailingPlacementPosition placePosition
)
Visual Basic
Public Shared Function Create ( _
	document As Document, _
	stairsOrRampId As ElementId, _
	railingTypeId As ElementId, _
	placePosition As RailingPlacementPosition _
) As ICollection(Of ElementId)
Visual C++
public:
static ICollection<ElementId^>^ Create(
	Document^ document, 
	ElementId^ stairsOrRampId, 
	ElementId^ railingTypeId, 
	RailingPlacementPosition placePosition
)

Parameters

document
Type: Autodesk.Revit.DBDocument
The document.
stairsOrRampId
Type: Autodesk.Revit.DBElementId
The stairs or ramp to which the new railing will host. The stairs or ramp should have no associated railings yet. If the stairs are a part of MultistoryStairs element railings will be populated on all levels.
railingTypeId
Type: Autodesk.Revit.DBElementId
The railing type of the new railing to be created.
placePosition
Type: Autodesk.Revit.DB.ArchitectureRailingPlacementPosition
The placement position of the new railing.

Return Value

The new railing instances successfully created on the stairs.

Examples

CopyC#
private void CreateRailing(Document document, Stairs stairs)
{
    using (Transaction trans = new Transaction(document, "Create Railings"))
    {
        trans.Start();

        // Delete existing railings
        ICollection<ElementId> railingIds = stairs.GetAssociatedRailings();
        foreach (ElementId railingId in railingIds)
        {
            document.Delete(railingId);
        }
        // Find RailingType
        FilteredElementCollector collector = new FilteredElementCollector(document);
        ICollection<ElementId> RailingTypeIds = collector.OfClass(typeof(RailingType)).ToElementIds();
        Railing.Create(document, stairs.Id, RailingTypeIds.First(), RailingPlacementPosition.Treads);
        trans.Commit();
    }
}
CopyVB.NET
Private Sub CreateRailing(document As Document, stairs As Stairs)
    Using trans As New Transaction(document, "Create Railings")
        trans.Start()

        ' Delete existing railings
        Dim railingIds As ICollection(Of ElementId) = stairs.GetAssociatedRailings()
        For Each railingId As ElementId In railingIds
            document.Delete(railingId)
        Next
        ' Find RailingType
        Dim collector As New FilteredElementCollector(document)
        Dim RailingTypeIds As ICollection(Of ElementId) = collector.OfClass(GetType(RailingType)).ToElementIds()
        Railing.Create(document, stairs.Id, RailingTypeIds.First(), RailingPlacementPosition.Treads)
        trans.Commit()
    End Using
End Sub

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentException The stairsOrRampId is not a stairs or ramp element. -or- The railingTypeId is not a railing type.
Autodesk.Revit.ExceptionsArgumentNullException A non-optional argument was null
Autodesk.Revit.ExceptionsArgumentOutOfRangeException A value passed for an enumeration argument is not a member of that enumeration
Autodesk.Revit.ExceptionsInvalidOperationException The stairsOrRampId already has associated railings or is in editing mode so association of railings is not permitted.
Autodesk.Revit.ExceptionsModificationForbiddenException The document is in failure mode: an operation has failed, and Revit requires the user to either cancel the operation or fix the problem (usually by deleting certain elements). -or- The document is being loaded, or is in the midst of another sensitive process.
Autodesk.Revit.ExceptionsModificationOutsideTransactionException The document has no open transaction.

See Also

ArchiLabs

Stop fighting Revit automation.

Build repeatable BIM design and documentation workflows with scripts, data, and AI in one place, without wrestling brittle one-off automations.

Try ArchiLabs →