Python script creates 2 stairs?

Hi everyone,

I’m trying to create a simple stairs using a python script. The script I have now is functional, however it creates two staircases with a different “actual tread depth” value.
Note that I do not fully understand transactions and processes within python and RevitAPI. I copied some lines of code from the following link: https://forum.dynamobim.com/t/stairs-disappearing-via-python/32952/3?u=pieter.lamoen

This is my code:

# Import libraries
import sys
import clr

# Import Dynamo Geometry Nodes
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import*

# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

# Import RevitAPI
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import*
from Autodesk.Revit.UI import*
from Autodesk.Revit.DB.Architecture import StairsRun
from Autodesk.Revit.DB.Architecture import StairsRunJustification

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager
# Define Current Document
doc = DocumentManager.Instance.CurrentDBDocument

# Define something???
class StairsFailurePreprocessor2( IFailuresPreprocessor ):
    def PreprocessFailures(self, failuresAccessor):		
	   return FailureProcessingResult.Continue  
# /// This is where the fun starts ///
# INPUT
baseLevel = UnwrapElement(IN[0])
nextLevel = UnwrapElement(IN[1])
line = IN[2].ToRevitType()

just = StairsRunJustification.Center
# or input1 = UnwrapElement(IN[0])

# CODE
TransactionManager.Instance.ForceCloseTransaction()
newStairsScope = StairsEditScope(doc, 'New Stairs')
newStairsId = newStairsScope.Start( baseLevel.Id, nextLevel.Id)
# TRANSACTION
# Start Transaction
trans = Autodesk.Revit.DB.Transaction(doc, 'Stair Transaction')
trans.Start()

newRun = StairsRun.CreateStraightRun(doc, newStairsId, line, just)

trans.Commit()
newStairsScope.Commit(StairsFailurePreprocessor2())
# End Transaction
stair_d = doc.GetElement(newStairsId)
# OUTPUT
OUT = stair_d, newRun

And this is my dynamo script:

Any help is appreciated! :smiley:

Hello,
on your screenshot, only 1 staircase is created with a single stairs Run