Automatically creates new railings with the specified railing type on all sides of a stairs element.
Namespace: Autodesk.Revit.DB.Architecture
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2013
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- document
- Type: Autodesk.Revit.DB Document
The document.
- stairsId
- Type: Autodesk.Revit.DB ElementId
The stairs to which the new railing will host. The stairs should have no associated railings yet.
- railingTypeId
- Type: Autodesk.Revit.DB ElementId
The railing type of the new railing is to be created.
- placePosition
- Type: Autodesk.Revit.DB.Architecture RailingPlacementPosition
The placement position of the new railing.
Return Value
The new railing instances successfully created on the stairs.Examples

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();
}
}

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
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions ArgumentException | The stairsId is not a stairs or ramp element. -or- The railingTypeId is not a railing type. |
Autodesk.Revit.Exceptions ArgumentNullException | A non-optional argument was NULL |
Autodesk.Revit.Exceptions ArgumentOutOfRangeException | A value passed for an enumeration argument is not a member of that enumeration |
Autodesk.Revit.Exceptions InvalidOperationException | The stairsId already has associated railings or is in editing mode so association of railings is not permitted. |