MikeD
March 5, 2019, 4:06am
1
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:
I tried this code:
newStairsScope = StairsEditScope(doc, “New Stairs”)
newStairsId = newStairsScope.Start( getLevelId(int(levelBot)), getLevelId(int(levelTop)) )
TransactionManager.Instance.EnsureInTransaction(doc)
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 = 20 …
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. ”
…
Dear All,
I have been trying to create a spiral Stair using the code below. I am feeding in the data as coordinates by using a json file. Even though the drawing created from the data looks correct I am still getting an error message: Cannot finish run sketch. Run sketch cannot have a riser segment intersecting the boundary at more than 2 points.
Any ideas what is going wrong?
[image]
[Stair_drg]
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)
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