import clr
# Add references to the Revit API
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
# Import necessary classes from Revit API and RevitServices
from Autodesk.Revit.DB import Document, FilteredElementCollector, BuiltInCategory
from Autodesk.Revit.DB.Architecture import Stairs, StairsRun
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Get the active document
doc = DocumentManager.Instance.CurrentDBDocument
# Method to get the parent stairs of a given stairs run
def get_parent_stairs(stairs_run_id):
# Start a transaction (required for most Revit API actions)
TransactionManager.Instance.EnsureInTransaction(doc)
# Get the stairs run element
stairs_run = doc.GetElement(stairs_run_id)
# Check if the element is a stairs run
if not isinstance(stairs_run, StairsRun):
raise Exception("Element is not a StairsRun")
# Get the parent stairs of the run
parent_stairs = stairs_run.GetStairs()
# End the transaction
TransactionManager.Instance.TransactionTaskDone()
return parent_stairs
# Example usage:
# Replace 'stairs_run_element_id' with the actual ElementId of the stairs run
stairs_id= ElementId(IN[0]) # Example ElementId
parent_stairs = get_parent_stairs(stairs_id)
# Output the parent stairs
OUT = parent_stairs
Thank you so much Mike, the fixed code and the error message are shown below:
Warning: IronPythonEvaluator.EvaluateIronPythonScript failed。
Traceback (most recent call last):
File “”, line 39, in
TypeError: expected BuiltInParameter, got UnknownElement
import clr
# Add references to the Revit API
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
# Import necessary classes from Revit API and RevitServices
from Autodesk.Revit.DB import Document, FilteredElementCollector, BuiltInCategory,ElementId
from Autodesk.Revit.DB.Architecture import Stairs, StairsRun
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Get the active document
doc = DocumentManager.Instance.CurrentDBDocument
# Method to get the parent stairs of a given stairs run
def get_parent_stairs(stairs_run_id):
# Start a transaction (required for most Revit API actions)
TransactionManager.Instance.EnsureInTransaction(doc)
# Get the stairs run element
stairs_run = doc.GetElement(stairs_run_id)
# Check if the element is a stairs run
if not isinstance(stairs_run, StairsRun):
raise Exception("Element is not a StairsRun")
# Get the parent stairs of the run
parent_stairs = stairs_run.GetStairs()
# End the transaction
TransactionManager.Instance.TransactionTaskDone()
return parent_stairs
# Example usage:
# Replace 'stairs_run_element_id' with the actual ElementId of the stairs run
stairs_id= ElementId(IN[0]) # Example ElementId
parent_stairs = get_parent_stairs(stairs_id)
# Output the parent stairs
OUT = parent_stairs
Thank you, Mike! The Script runs perfectly when inputting a single stair run, now we are trying to make it work when we input a list of stair runs
import clr
# Add references to the Revit API
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
# Import necessary classes from Revit API and RevitServices
from Autodesk.Revit.DB import Document, FilteredElementCollector, BuiltInCategory,ElementId
from Autodesk.Revit.DB.Architecture import Stairs, StairsRun
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Get the active document
doc = DocumentManager.Instance.CurrentDBDocument
# Method to get the parent stairs of a given stairs run
def get_parent_stairs(stairs_run_id):
# Start a transaction (required for most Revit API actions)
TransactionManager.Instance.EnsureInTransaction(doc)
# Get the stairs run element
stairs_run = doc.GetElement(stairs_run_id)
# Check if the element is a stairs run
if not isinstance(stairs_run, StairsRun):
raise Exception("Element is not a StairsRun")
# Get the parent stairs of the run
parent_stairs = stairs_run.GetStairs()
# End the transaction
TransactionManager.Instance.TransactionTaskDone()
return parent_stairs
# Example usage:
# Replace 'stairs_run_element_id' with the actual ElementId of the stairs run
stairs_id= UnwrapElement(IN[0]).Id # Example ElementId
parent_stairs = get_parent_stairs(stairs_id)
# Output the parent stairs
OUT = parent_stairs
Here are the script we are working on now, but both of them aren’t working well now.
import clr
# Add references to the Revit API
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
# Import necessary classes from Revit API and RevitServices
from Autodesk.Revit.DB import Document, FilteredElementCollector, BuiltInCategory,ElementId
from Autodesk.Revit.DB.Architecture import Stairs, StairsRun
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Get the active document
doc = DocumentManager.Instance.CurrentDBDocument
# Method to get the parent stairs of a given stairs run
def get_parent_stairs(stairs_run):
# Start a transaction (required for most Revit API actions)
TransactionManager.Instance.EnsureInTransaction(doc)
# Check if the input is a single StairsRun or a list of StairsRun
if isinstance(stairs_run, list):
stairs = []
for run in stairs_run:
if not isinstance(run, StairsRun):
raise Exception("Element is not a StairsRun")
# Get the parent stairs of the run
stairs.extend(run.GetStairs())
else:
if not isinstance(stairs_run, StairsRun):
raise Exception("Element is not a StairsRun")
stairs = stairs_run.GetStairs()
# End the transaction
TransactionManager.Instance.TransactionTaskDone()
return stairs
# Example usage:
# Replace 'stairs_run_element_id' with the actual ElementId of the stairs run
stairs_run_elements = UnwrapElement(IN[0]).Id # List of StairsRun elements
# Get the parent stairs for each StairsRun element
parent_stairs = get_parent_stairs(stairs_run_elements)
# Output the parent stairs
OUT = parent_stairs
import clr
# Add references to the Revit API
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
# Import necessary classes from Revit API and RevitServices
from Autodesk.Revit.DB import Document, FilteredElementCollector, BuiltInCategory,ElementId
from Autodesk.Revit.DB.Architecture import StairsRun
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Get the active document
doc = DocumentManager.Instance.CurrentDBDocument
# Method to get the parent stairs of a given stairs run
def get_parent_stairs(stairs_runs):
parent_stairs = []
# Start a transaction (required for most Revit API actions)
TransactionManager.Instance.EnsureInTransaction(doc)
# Iterate through each StairsRun element in the input list
for stairs_run in stairs_runs:
if not isinstance(stairs_run, StairsRun):
raise ValueError("Input must be a list of StairsRun elements.")
# Get the parent stairs of the run
stairs = stairs_run.GetStairs()
parent_stairs.extend(stairs)
# End the transaction
TransactionManager.Instance.TransactionTaskDone()
return parent_stairs
# Example usage:
stairs_run_elements = UnwrapElement(IN[0]).Id # List of StairsRun elements
# Get the parent stairs for each StairsRun element
parent_stairs = get_parent_stairs(stairs_run_elements)
# Output the parent stairs
OUT = parent_stairs
above script show the message below:
Traceback (most recent call last):
File “”, line 42, in
File “”, line 31, in get_parent_stairs
TypeError: Stairs is not iterable
You are going to have to tailor the script to iterate over the input and decide what format that is going to be - say integers or elements
# Check for list
if not hasattr(IN[0], "__iter__"):
IN[0] = [IN[0]]
# Id integers
stairs_run_elements = [ElementId(item) for item in IN[0]]
# Selected elements
stairs_run_elements = [item.Id for item in UnwrapElement(IN[0])]
Modify parent_stairs.extend(stairs) line as extend is used to join a list (or other iterable) to a list