Create stairs with python script,use revitapi,proplem of newStairsScope.IsPermitted and warnings

I use the follow code to create stairs in revit by dynamo.It seems work but not work well.I have met two problem.
1、It’s very strange that newStairsScope.IsPermitted 's value is false,I just open a new file and run my script,I think it don’t have the condition like“StairsEditScope is not permitted to start at this moment for one of the following reasons: The document is in read-only state, or the document is currently modifiable, or there already is a stairs edit mode active in the document. ”
2、It always show me the following dialog,how to avoid this.
image
I code is following:

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 *

#该节点的输入内容将存储为 IN 变量中的一个列表。

class StairsFailurePreprocessor( IFailuresPreprocessor ):
def PreprocessFailures(failuresAccessor):
failList = failuresAccessor.GetFailureMessages()
for failure in failList:
failuresAccessor.DeleteWarning(failure)
return FailureProcessingResult.Continue

levelBottom=IN[0]
levelTop=IN[1]
“”

doc = DocumentManager.Instance.CurrentDBDocument
a = StairsFailurePreprocessor()
newStairsScope = StairsEditScope(doc, ‘New Stairs’)
if newStairsScope.IsPermitted==False:
TaskDialog.Show(‘提示’,‘不允许开始编辑楼梯’)

newStairsId = newStairsScope.Start(ElementId(levelBottom.Id),ElementId(levelTop.Id))
ele=doc.GetElement(newStairsId)
#timiangaodu=ele.LookupParameter(‘实际踢面高度’).AsDouble()
#tabu=ele.LookupParameter(‘实际踏步深度’).AsDouble()
#trans0=TransactionManager.Instance.EnsureInTransaction(doc)
#trans0.EnsureInTransaction(doc)
#options=trans0.GetFailureHandlingOptions()
#options.SetFailuresPreprocessor(a)
#tans0.SetFailureHandlingOptions(options);
trans = Autodesk.Revit.DB.Transaction(doc, “Temp Transaction”)
trans.Start()

if doc.IsModifiable ==False:
TaskDialog.Show(‘提示’,‘doc cont modify’)
#options=trans.GetFailureHandlingOptions()
#options.SetFailuresPreprocessor(a)
#trans.SetFailureHandlingOptions(options);
“”
#newRun1以草图方式去创建楼梯
bdryCurves = list()
riserCurves = list()
pathCurves = list()
pnt1 = XYZ(0,0,0)
pnt2 = XYZ(15,0,0)
pnt3 = XYZ(0,10,0)
pnt4 = XYZ(15,10,0)
#boundary
bdryCurves.append(Line.CreateBound(pnt1, pnt2))
bdryCurves.append(Line.CreateBound(pnt3, pnt4))
#riser curves
riserNum = 15
for ii in range(0,16):
end0 = (pnt1 + pnt2) * ii / float(riserNum)
end1 = (pnt3 + pnt4) * ii / float(riserNum)
end2 = XYZ(end1.X,10,0)
riserCurves.append(Line.CreateBound(end0,end2))

pathEnd0 = (pnt1 + pnt3) / 2.0
pathEnd1 = (pnt2 + pnt4) / 2.0
pathCurves.append(Line.CreateBound(pathEnd0, pathEnd1))

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

locationLine = Line.CreateBound(XYZ(20, -5, newRun1.TopElevation), XYZ(35, -5, newRun1.TopElevation))
TaskDialog.Show(‘提示’,str(newRun1.TopElevation))

#Add a landing between the runs
landingLoop = CurveLoop()
p1 = XYZ(15, 10, 0)
p2 = XYZ(20, 10, 0)
p3 = XYZ(20, -10, 0)
p4 = XYZ(15, -10, 0)
curve_1 = Line.CreateBound(p1, p2)
curve_2 = Line.CreateBound(p2, p3)
curve_3 = Line.CreateBound(p3, p4)
curve_4 = Line.CreateBound(p4, p1)
landingLoop.Append(curve_1)
landingLoop.Append(curve_2)
landingLoop.Append(curve_3)
landingLoop.Append(curve_4)
newLanding = StairsLanding.CreateSketchedLanding(doc, newStairsId, landingLoop, newRun1.TopElevation)

newRun2 = StairsRun.CreateStraightRun(doc, newStairsId, locationLine, StairsRunJustification.Center)
newRun2.ActualRunWidth = 10
TaskDialog.Show(‘提示’,str(newRun2.TopElevation))

#TransactionManager.Instance.TransactionTaskDone()
#TransactionManager.Instance.ForceCloseTransaction()
trans.Commit()
trans.Dispose()
newStairsScope.Commit(a)
newStairsScope.Dispose()
#将输出内容指定给 OUT 变量。
OUT = newStairsId

Hi @358149732,

I’m also trying to create stairs in a similar way & am running into issues.
I’ve posted my code here - Node to create stair
Let me know if you were able to solve your issue.

Thank you,
MikeD

See here