StairsEditScope Class

StairsEditScope Class

StairsEditScope allows user to maintain a stairs-editing session.
Inheritance Hierarchy
SystemObject
  Autodesk.Revit.DBEditScope
    Autodesk.Revit.DBStairsEditScope

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public class StairsEditScope : EditScope
Public Class StairsEditScope
	Inherits EditScope
public ref class StairsEditScope : public EditScope
type StairsEditScope = 
    class
        inherit EditScope
    end

The StairsEditScope type exposes the following members.

Constructors
 NameDescription
Public methodStairsEditScope Instantiates a StairsEditScope object.
Top
Properties
 NameDescription
Public propertyIsActive Tells if the EditScope is active. In other words, the EditScope has started but not committed/canceled yet.
(Inherited from EditScope)
Public propertyIsPermitted Tells if the edit scope is permitted to start.
(Inherited from EditScope)
Public propertyIsValidObject Specifies whether the .NET object represents a valid Revit entity.
(Inherited from EditScope)
Top
Methods
 NameDescription
Public methodCancel Cancels the edit scope.
(Inherited from EditScope)
Public methodCommit Finishes the edit scope.
(Inherited from EditScope)
Public methodDispose
(Inherited from EditScope)
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodStart(ElementId) Starts an stairs edit mode for an existing Stairs element
Public methodStart(ElementId, ElementId) Creates a new empty stairs element with a default stairs type in the specified levels and then starts stairs edit mode and editing the new stairs.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Remarks
Start/end of a StairsEditScope will start/end a transaction group. After a StairsEditScope is started, user can start transactions and edit the stairs. Individual transactions the user creates inside StairsEditScope will not appear in the undo menu. All transactions committed during the edit mode will be merged into a single one which will bear the given name passed into StairsEditScope constructor.
Example
private ElementId CreateStairs(Document document, Level levelBottom, Level levelTop)
{
    ElementId newStairsId = null;

    using (StairsEditScope newStairsScope = new StairsEditScope(document, "New Stairs"))
    {
        newStairsId = newStairsScope.Start(levelBottom.Id, levelTop.Id);

        using (Transaction stairsTrans = new Transaction(document, "Add Runs and Landings to Stairs"))
        {
            stairsTrans.Start();

            // Create a sketched run for the stairs
            IList<Curve> bdryCurves = new List<Curve>();
            IList<Curve> riserCurves = new List<Curve>();
            IList<Curve> pathCurves = new List<Curve>();
            XYZ pnt1 = new XYZ(0, 0, 0);
            XYZ pnt2 = new XYZ(15, 0, 0);
            XYZ pnt3 = new XYZ(0, 10, 0);
            XYZ pnt4 = new XYZ(15, 10, 0);

            // boundaries       
            bdryCurves.Add(Line.CreateBound(pnt1, pnt2));
            bdryCurves.Add(Line.CreateBound(pnt3, pnt4));

            // riser curves
            const int riserNum = 20;
            for (int ii = 0; ii <= riserNum; ii++)
            {
                XYZ end0 = (pnt1 + pnt2) * ii / (double)riserNum;
                XYZ end1 = (pnt3 + pnt4) * ii / (double)riserNum;
                XYZ end2 = new XYZ(end1.X, 10, 0);
                riserCurves.Add(Line.CreateBound(end0, end2));
            }

            //stairs path curves
            XYZ pathEnd0 = (pnt1 + pnt3) / 2.0;
            XYZ pathEnd1 = (pnt2 + pnt4) / 2.0;
            pathCurves.Add(Line.CreateBound(pathEnd0, pathEnd1));

            StairsRun newRun1 = StairsRun.CreateSketchedRun(document, newStairsId, levelBottom.Elevation, bdryCurves, riserCurves, pathCurves);

            // Add a straight run
            Line locationLine = Line.CreateBound(new XYZ(20, -5, newRun1.TopElevation), new XYZ(35, -5, newRun1.TopElevation));
            StairsRun newRun2 = StairsRun.CreateStraightRun(document, newStairsId, locationLine, StairsRunJustification.Center);
            newRun2.ActualRunWidth = 10;

            // Add a landing between the runs
            CurveLoop landingLoop = new CurveLoop();
            XYZ p1 = new XYZ(15, 10, 0); 
            XYZ p2 = new XYZ(20, 10, 0);
            XYZ p3 = new XYZ(20, -10, 0);
            XYZ p4 = new XYZ(15, -10, 0);
            Line curve_1 = Line.CreateBound(p1, p2);
            Line curve_2 = Line.CreateBound(p2, p3);
            Line curve_3 = Line.CreateBound(p3, p4);
            Line curve_4 = Line.CreateBound(p4, p1);

            landingLoop.Append(curve_1);
            landingLoop.Append(curve_2);
            landingLoop.Append(curve_3);
            landingLoop.Append(curve_4);
            StairsLanding newLanding = StairsLanding.CreateSketchedLanding(document, newStairsId, landingLoop, newRun1.TopElevation);

            stairsTrans.Commit();
        }
        // A failure preprocessor is to handle possible failures during the edit mode commitment process.
        newStairsScope.Commit(new StairsFailurePreprocessor());
    }

    return newStairsId;
}
Private Function CreateStairs(document As Document, levelBottom As Level, levelTop As Level) As ElementId
    Dim newStairsId As ElementId = Nothing

    Using newStairsScope As New StairsEditScope(document, "New Stairs")
        newStairsId = newStairsScope.Start(levelBottom.Id, levelTop.Id)

        Using stairsTrans As New Transaction(document, "Add Runs and Landings to Stairs")
            stairsTrans.Start()

            ' Create a sketched run for the stairs
            Dim bdryCurves As IList(Of Curve) = New List(Of Curve)()
            Dim riserCurves As IList(Of Curve) = New List(Of Curve)()
            Dim pathCurves As IList(Of Curve) = New List(Of Curve)()
            Dim pnt1 As New XYZ(0, 0, 0)
            Dim pnt2 As New XYZ(15, 0, 0)
            Dim pnt3 As New XYZ(0, 10, 0)
            Dim pnt4 As New XYZ(15, 10, 0)

            ' boundaries       
            bdryCurves.Add(Line.CreateBound(pnt1, pnt2))
            bdryCurves.Add(Line.CreateBound(pnt3, pnt4))

            ' riser curves
            Const riserNum As Integer = 20
            For ii As Integer = 0 To riserNum
                Dim end0 As XYZ = (pnt1 + pnt2) * ii / CDbl(riserNum)
                Dim end1 As XYZ = (pnt3 + pnt4) * ii / CDbl(riserNum)
                Dim end2 As New XYZ(end1.X, 10, 0)
                riserCurves.Add(Line.CreateBound(end0, end2))
            Next

            'stairs path curves
            Dim pathEnd0 As XYZ = (pnt1 + pnt3) / 2.0
            Dim pathEnd1 As XYZ = (pnt2 + pnt4) / 2.0
            pathCurves.Add(Line.CreateBound(pathEnd0, pathEnd1))

            Dim newRun1 As StairsRun = StairsRun.CreateSketchedRun(document, newStairsId, levelBottom.Elevation, bdryCurves, riserCurves, pathCurves)

            ' Add a straight run
            Dim locationLine As Line = Line.CreateBound(New XYZ(20, -5, newRun1.TopElevation), New XYZ(35, -5, newRun1.TopElevation))
            Dim newRun2 As StairsRun = StairsRun.CreateStraightRun(document, newStairsId, locationLine, StairsRunJustification.Center)
            newRun2.ActualRunWidth = 10

            ' Add a landing between the runs
            Dim landingLoop As New CurveLoop()
            Dim p1 As New XYZ(15, 10, 0)
            Dim p2 As New XYZ(20, 10, 0)
            Dim p3 As New XYZ(20, -10, 0)
            Dim p4 As New XYZ(15, -10, 0)
            Dim curve_1 As Line = Line.CreateBound(p1, p2)
            Dim curve_2 As Line = Line.CreateBound(p2, p3)
            Dim curve_3 As Line = Line.CreateBound(p3, p4)
            Dim curve_4 As Line = Line.CreateBound(p4, p1)

            landingLoop.Append(curve_1)
            landingLoop.Append(curve_2)
            landingLoop.Append(curve_3)
            landingLoop.Append(curve_4)
            Dim newLanding As StairsLanding = StairsLanding.CreateSketchedLanding(document, newStairsId, landingLoop, newRun1.TopElevation)

            stairsTrans.Commit()
        End Using
        ' A failure preprocessor is to handle possible failures during the edit mode commitment process.
        newStairsScope.Commit(New StairsFailurePreprocessor())
    End Using

    Return newStairsId
End Function

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also