The Autodesk.Revit.DB.Architecture.Railing class represents a railing element in an Autodesk Revit project. Although railings are associated with stairs, they can be associated with another host, such as a floor, or placed in space. Railings can be continuous or non-continuous. If they are non-continuous, only a limited level of access is provided.
Railings associated with stairs can be retrieved from the Stairs class with the GetAssociatedRailings() method. There are only a few properties and methods specific to railings such as the TopRail property which returns the ElementId of the top rail and Flipped which indicates if the Railing is flipped. The Railing.Flip() method flips the railing, while the RemoveHost() method will remove the association between the railing and its host.
The following example retrieves all of the railings associated with a Stairs object and flips each railing that is the default railing that the system generates.
Code Region: Working with Railings |
private void FlipDefaultRailings(Stairs stairs) { ICollection<ElementId> railingIds = stairs.GetAssociatedRailings(); Transaction trans = new Transaction(stairs.Document, "Flip Railings"); trans.Start(); foreach (ElementId railingId in railingIds) { Railing railing = stairs.Document.GetElement(railingId) as Railing; if (railing.IsDefault == true) { railing.Flip(); } } trans.Commit(); } |
The Railing class has a Create method which automatically creates new railings with the specified railing type on all sides of a stairs element. Railing creation is demonstrated in the Creating and Editing Stairs section.
The RailingType class represents the railing type used in the generation of a railing. It contains a number of properties about the railing, such as the height, lateral offset and type of the primary and secondary handrails as well as the top rail.
Code Region: RailingType |
private void GetRailingType(Stairs stairs) { ICollection<ElementId> railingIds = stairs.GetAssociatedRailings(); foreach (ElementId railingId in railingIds) { Railing railing = stairs.Document.GetElement(railingId) as Railing; RailingType railingType = stairs.Document.GetElement(railing.GetTypeId()) as RailingType; // Format railing type info for display string info = "Railing Type: " + railingType.Name; info += "\nPrimary Handrail Height: " + railingType.PrimaryHandrailHeight; info += "\nTop Rail Height: " + railingType.TopRailHeight; TaskDialog.Show("Revit", info); } } |