Stairs Disappearing via Python

Hi All,

I have been struggling with creating stairs via Python. I am using the same references as many - pulling from the autodesk knowledge network example & other posts. See below for examples I’m using as guides. I have gotten passed most visible errors - but the stairs do not stay / commit. This seemed to be other users’ problems but my .Commit() line does not seem to be working.

If you copy & paste my current code - it runs without errors but the stairs do not appear. If you change the riserNum - the stairs appear grayed out with an error message. Once the math is correct (riserNum) the stairs do not stay.

Thanks in advance to anyone with advice.

current code:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit

clr.AddReference('RevitAPIUI')

from Autodesk.Revit.UI import TaskDialog
clr.AddReference('RevitAPI')
import Autodesk

from Autodesk.Revit.DB import IFailuresPreprocessor
from Autodesk.Revit.DB import StairsEditScope
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import Parameter
from Autodesk.Revit.DB.Architecture import StairsRun
from Autodesk.Revit.DB.Architecture import *

class StairsFailurePreprocessor( IFailuresPreprocessor ):
    def PreprocessFailures(failuresAccessor):
        return FailureProcessingResult.Continue

baseLevel = UnwrapElement(IN[0])
nextLevel = UnwrapElement(IN[5])

doc = DocumentManager.Instance.CurrentDBDocument
a = StairsFailurePreprocessor()

trans = Autodesk.Revit.DB.Transaction(doc, 'Stair Transaction')
newStairsScope = StairsEditScope(doc, 'New Stairs')
newStairsId = newStairsScope.Start( baseLevel.Id, nextLevel.Id)

#TransactionManager.Instance.EnsureInTransaction(doc)

trans.Start()

bdryCurves = list()
riserCurves = list()
pathCurves = list()

pt5 = XYZ(0,0,0)
pt6 = XYZ(15,0,0)
pt7 = XYZ(0,10,0)
pt8 = XYZ(15,10,0)

#boundary

bdryCurves.append(Line.CreateBound(pt5, pt6))
bdryCurves.append(Line.CreateBound(pt7, pt8))

#riser curves
riserNum = 17
for ii in range(0, 18):

end0 = (pt5 + pt6) * ii / float(riserNum)
end1 = (pt7 + pt8) * ii / float(riserNum)
end2 = XYZ(end1.X, 10, 0)
riserCurves.append(Line.CreateBound(end0,end2))

pathEnd0 = (pt5 + pt7) / 2.0
pathEnd1 = (pt6 + pt8) / 2.0
pathCurves.append(Line.CreateBound(pathEnd0, pathEnd1))

newRun1 = StairsRun.CreateSketchedRun(doc, newStairsId , baseLevel.Elevation , bdryCurves, riserCurves, pathCurves )

trans.Commit()
trans.Dispose()

#TransactionManager.Instance.EnsureInTransaction(doc)
#TransactionManager.Instance.TransactionTaskDone()

newStairsScope.Commit(a)
#newStairsScope.Commit(new StairsFailurePreprocessor() )
#newStairsScope.Dispose()

#OUT = newStairsId

related posts:

1 Like

Hello Mike, i’m struggling with the same problem. Did you get any further with this script to create a stair?
Wouter Hilhorst

Hello
there is a missing parameter in the class PreprocessFailures function.
failuresAccessor without any other parameter becomes in fact the current instance of the class (which we must name “self” by convention in Python), you must therefore add a second parameter (whatever its name)

create stairs run

corrected code

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import StairsRun
			
class StairsFailurePreprocessor2( IFailuresPreprocessor ):
    def PreprocessFailures(self, failuresAccessor):		
		return FailureProcessingResult.Continue    

baseLevel = UnwrapElement(IN[0])
nextLevel = UnwrapElement(IN[1])
riserNum = IN[2]

TransactionManager.Instance.ForceCloseTransaction()

newStairsScope = StairsEditScope(doc, 'New Stairs')
newStairsId = newStairsScope.Start( baseLevel.Id, nextLevel.Id)


trans = Autodesk.Revit.DB.Transaction(doc, 'Stair Transaction')
trans.Start()

bdryCurves = list()
riserCurves = list()
pathCurves = list()

pt1 = XYZ(0,0,0)
pt2 = XYZ(15,0,0)
pt3 = XYZ(0,10,0)
pt4 = XYZ(15,10,0)

#boundary

bdryCurves.append(Line.CreateBound(pt1, pt2))
bdryCurves.append(Line.CreateBound(pt3, pt4))

#riser curves
for ii in range(riserNum):
	end0 = (pt1 + pt2) * ii / float(riserNum - 1)
	end1 = (pt3 + pt4) * ii / float(riserNum - 1)
	end2 = XYZ(end1.X, 10, 0)
	riserCurves.append(Line.CreateBound(end0,end2))

pathEnd0 = (pt1 + pt3) / 2.0
pathEnd1 = (pt2 + pt4) / 2.0
pathCurves.append(Line.CreateBound(pathEnd0, pathEnd1))

newRun1 = StairsRun.CreateSketchedRun(doc, newStairsId , baseLevel.Elevation , bdryCurves, riserCurves, pathCurves )
trans.Commit()
newStairsScope.Commit(StairsFailurePreprocessor2())

OUT = newRun1
6 Likes