Python programming

Hi, I am trying to create staircase in dynamo using python program.
The code is as below*

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Debugging
print("Starting Dynamo Python script")

try:
    # Get the current Revit document
    doc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document
    print("Document loaded.")

    # Inputs from Dynamo (unwrap the elements)
    level_start = UnwrapElement(IN[0])  # Base Level
    print(f"Base Level: {level_start}")

    level_end = UnwrapElement(IN[1])    # Top Level
    print(f"Top Level: {level_end}")

    stair_location_curve = UnwrapElement(IN[2])  # Location Curve
    print(f"Stair Location Curve: {stair_location_curve}")

    stair_type = UnwrapElement(IN[3])   # Stair Type
    print(f"Stair Type: {stair_type}")

    riser_height = float(IN[4])  # Ensure riser height is a float
    tread_depth = float(IN[5])   # Ensure tread depth is a float

    # Start a transaction in Revit
    TransactionManager.Instance.EnsureInTransaction(doc)

    # Create the stairs
    stairs = Stairs.Create(doc, stair_type.Id, level_start.Id, level_end.Id)
    print("Stairs created successfully.")

    # Commit the transaction
    TransactionManager.Instance.TransactionTaskDone()

    # Output the result
    OUT = stairs

except Exception as e:
    # Catch and output the error
    OUT = f"Error: {e}"
    print(f"Error: {e}")

There is error message that is openparenexpected.
Can someone please help me solve this problem?  
Thank you in advance.

Not that much in to Revit and Python but can you explain a little bit more what issue that appears and what you need help with? Is it your code or did you found it somewhere and need to evaluate it and develop it further?

1 Like

ChatGPT hallucinating again?
There is no Stairs.Create method. Unless you’ve defined your own.

Stairs with the API are much more involved than this.
Start with StairsEditScope.
https://help.autodesk.com/view/RVT/2025/ENU/?guid=Revit_API_Revit_API_Developers_Guide_Revit_Geometric_Elements_Stairs_and_Railings_Creating_and_Editing_Stairs_html

1 Like