Manage

Select

Model

Analyze

Collaborate

Stay up to date

Interact

Run Python

The "Run Python" command in BIMO Add-in for Revit allows users to execute Python scripts directly within Autodesk Revit. This provides an opportunity to automate tasks, perform complex calculations, and manipulate Revit elements using Python code.

Configuration Settings

Upon activating the command, users can input their custom Python script. The script will be executed in the context of the current Revit document. The following sections explain how to set up and execute Python scripts with access to Revit API objects.

  • Execution Engine :

    Execution Engine :

    Choose between IronPython and Dynamo_CPython3. IronPython provides access to Revit API globals such as __doc__ and __uidoc__. Dynamo_CPython3 does not expose these globals but runs code similarly to a Python node in Dynamo.

    Choose between IronPython and Dynamo_CPython3. IronPython provides access to Revit API globals such as __doc__ and __uidoc__. Dynamo_CPython3 does not expose these globals but runs code similarly to a Python node in Dynamo.

  • Script file :

    Script file :

    Optional path to a Python file. If the Script field is empty, the code from this file will be executed.

    Optional path to a Python file. If the Script field is empty, the code from this file will be executed.

  • Script :

    Script :

    Enter the Python script to execute. Both engines support the use of IN for inputs and OUT for the output result. The code is run either from this field or from the specified file if this field is empty.

    Enter the Python script to execute. Both engines support the use of IN for inputs and OUT for the output result. The code is run either from this field or from the specified file if this field is empty.

  • IN :

    IN :

    A list of string inputs provided by the user. These values can be accessed in the script via the IN variable.

    A list of string inputs provided by the user. These values can be accessed in the script via the IN variable.

Available Variables

The following variables are available depending on the selected execution engine:

  • IN :

    IN :

    A list of input strings provided via the configuration panel. Available in both IronPython and Dynamo_CPython3.

    A list of input strings provided via the configuration panel. Available in both IronPython and Dynamo_CPython3.

  • OUT :

    OUT :

    The final result or message from the script. The command system displays this value upon script completion.

    The final result or message from the script. The command system displays this value upon script completion.

  • __doc__ :

    __doc__ :

    Available only in IronPython. Refers to the active Document in Revit.

    Available only in IronPython. Refers to the active Document in Revit.

  • __uidoc__ :

    __uidoc__ :

    Available only in IronPython. Refers to the UIDocument object for interacting with the UI layer.

    Available only in IronPython. Refers to the UIDocument object for interacting with the UI layer.

  • __revit__, __uiapp__ :

    __revit__, __uiapp__ :

    Also available only in IronPython. Provide references to the broader Revit application context.

    Also available only in IronPython. Provide references to the broader Revit application context.

Executing the Script

After setting the desired script and inputs, click the "OK" button to run the script. The result will be shown in a dialog box.

  • Returning Output :

    Returning Output :

    To return a result or message from the script, assign a value to the OUT variable. For example:

    OUT = "Processed {0} elements".format(element_count)
    This message will be shown in the result dialog.

    To return a result or message from the script, assign a value to the OUT variable. For example:

    OUT = "Processed {0} elements".format(element_count)
    This message will be shown in the result dialog.

Post-Execution

If the script completes successfully, the output defined in OUT will be displayed in a task dialog. If an error occurs, a detailed message will be shown to help with troubleshooting.

An error has occurred. This app may no longer respond until reloaded. Reload 🗙