Stair Path Python script

Hello,

I am trying to revise the script that creates stair paths, which I found here:

but it’s really not my forte…

I have added another input IN[1], for the views to process. (line 27).

I have two questions:

  1. if I feed only one stair to the script, I get an error, because they need to be a list. How do I also allow single elements, for both stairs and views?
  2. Input IN[1] is the list of views. I doubled the “for” loop, adding a loop for the views, in line 49, however, I don’t know how to get the view ID (line 51)…

I am getting this error: image

Here is the (badly) revised script:

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

#Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk

#Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
from Autodesk.Revit.DB import *
from Autodesk.Revit.Creation import *
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)


doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
stairs = UnwrapElement(IN[0])
views = IN[1]
typelist = list()
newpaths = list()
TransactionManager.Instance.EnsureInTransaction(doc)


#find stairpathtype
collpathtype = FilteredElementCollector(doc)
filtpathtype = ElementCategoryFilter(BuiltInCategory.OST_StairsPaths)
stairpathtypes = collpathtype.WherePasses(filtpathtype).ToElements()

for stairpathtype in stairpathtypes:
	istype = stairpathtype.ToString()
	if istype == "Autodesk.Revit.DB.Architecture.StairsPathType":
		typelist.append(stairpathtype)

stairpathtype = typelist[0]
pathid = stairpathtype.Id


#create stair path for stair runs
for view in views:
	for stair in stairs:
		stairid = LinkElementId(stair.Id)
		newpath = Autodesk.Revit.DB.Architecture.StairsPath.Create(doc, stairid, pathid, view.ViewId)
		newpaths.append(newpath)


TransactionManager.Instance.TransactionTaskDone()

doc.Regenerate()
uidoc.RefreshActiveView()

OUT = newpaths

Thank you

reagrds

gio

Hello
a few comments

1 / replace this line

by

toList = lambda x : x if hasattr(x, "__iter__")  else [ x ]
views = UnwrapElement(toList(IN[0])) 

2/ replace view.ViewId by view.Id

3/ your Imports are uncompleted

4/ method to find the first stairpathtypeId

pathid = FilteredElementCollector(doc).OfClass(StairsPathType).WhereElementIsElementType().FirstElementId()

5/ add a check to make sure the view is a ‘floorPlan’ view to be created the path