I am trying to get all the stairs within a multistory stair. I’ve written a Python script but it is not returning all the individual stairs. I think if a stair has the same floor-to-floor height they must be grouped and only one instance is returned using the GetAllStairsIds command. There looks like there might be another command MultistoryStairsId but I’m not sure if this will do what I need it to do. Any thoughts?
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
stairs = IN[0]
#if not isinstance(stairs,list):
stairs = [stairs]
def getRuns(stair):
runs = []
stair = UnwrapElement(stair)
runids = stair.GetAllStairsIds()
for run in runids:
runs.append(doc.GetElement(run))
return runs
OUT = map(getRuns, stairs)
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
stairs = UnwrapElement(IN[0])
runs=[]
for s in stairs:
rid=s.GetAllStairsIds()
for r in rid:
runs.append(doc.GetElement(r))
OUT = runs
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 14, in
TypeError: iteration over non-sequence of type MultistoryStairs
Ewan I got your script to work with the Flatten node. But it gives me the same result as my first Python script. This screenshot shows the issue. It is one multistory stair but it only returns two stairs. I’m guessing because L1-L2 is the same as L2-L3 is has been grouped some how. What I am after is the 3 individual stairs returned (from a selected mutistory stair). Thats why I wondering if I needed to use the MultistoryStairsId command as well/ instead.
So I’ve done some more tests and I think I’ve identified the problem but still not sure the solution. If you use all elements of category, it still only returns two stairs. But if you unpin the stairs within the multistory stair, you get three stairs. So is there a way to return all three stairs using Dynamo without unpinning?
This element will contain one or more Stairs elements. These can be obtained via GetAllStairsIds and GetStairsOnLevel(ElementId). Stairs elements are either a reference instance which is copied to each level covered by groups of identical stairs instances which share the same level height, or individual Stairs instances which are not connected to a group with the same level height. By default, when adding new levels to the multistory stair, new stairs will be added to the group (shown in the Revit user interface with a ‘Pin’ icon).
For groups of duplicate stairs at different levels, the instances can be found as Subelements of the Stairs element (see GetSubelements .
Altering the elevation of any of the associated levels seems to expose multistory stair components.
The code below tries to do so, but it only seems to work on forcing Dynamo to re-execute by changing a value or variable (as demonstrated in the gif below)
The base Revit file is the same as the one provided above by @Paul_Wintour (Stair.rvt) and Dynamo is in Automatic Run mode
l = ElementQueries.OfCategory(Category.ByName("Levels"))[1];
a = l.GetParameterValueByName("Elevation");
b = l.SetParameterByName("Elevation",a+0.000);
c = ElementQueries.OfCategory(Category.ByName("Stairs"));
A slight alteration to the above code helps avoid any manual intervention.
Before executing the code…
On executing the code …
l = ElementQueries.OfCategory(Category.ByName("Levels"))[1];
a = l.GetParameterValueByName("Elevation");
b = Transaction.End(l.SetParameterByName("Elevation",a+0.005));
c = l.SetParameterByName("Elevation",Math.Round(a));
d = ElementQueries.OfCategory(Category.ByName("Stairs"));
Thanks @Vikram_Subbaiah but I’m not sure modifying levels is ideal. It opens up a whole can of worms. I was hoping to be able to use the GetSubelements method. It sounds like it should be possible. I got this far. There are no error warnings but its not returning any results.
@Ewan_Opie I can’t enlarge your image but when I run the script it returns the same stair element just repeated. It is only when you unpin one of the stairs, doesn’t the element change to the instance. So I think GetSubelements is still needed
Weird, now that I reopen the example Revit file it does exactly as you describe.
Here is an enlargement of the GIF from above (3 Element IDs)… Im baffled.