Run Python

Learn how to run Python scripts inside the active Revit session with BIMO presets, inputs, and model-change safeguards.

Run Python lets you run a Python script from BIMO inside the active Revit session. Use it for quick checks, small automation tasks, and repeatable workflows that you want to keep as a BIMO preset.

Warning: A Python script can change the Revit model. Test model-changing scripts on a copy or a safe test file first.

Before You Run

  • Open the Revit project or family you want to work with.

  • Check that the script is intended for the active document.

  • If the script changes the model, make sure it opens and commits its own Revit transaction.

Command Settings

Setting

What It Does

Execution Engine

Chooses how the script is run: IronPython or Dynamo_CPython3.

Script file

Optional path to a .py file. BIMO reads this file only when Script is empty.

Script

Python code entered directly in the command settings. If this field is not empty, BIMO runs it instead of Script file.

IN

A list of text input values passed to the script.

Choosing an Engine

Use IronPython when the script needs direct access to the active Revit document through BIMO variables such as __doc__, __uidoc__, or __uiapp__.

Use Dynamo_CPython3 for scripts written in the style of a Dynamo Python node, using IN for input and OUT for output.

Warning: Dynamo_CPython3 does not provide __doc__, __uidoc__, __revit__, or __uiapp__. If the Dynamo UI is already open, BIMO may ask you to close it before running the script.

Values Available in the Script

Value

Available In

Meaning

IN

IronPython, Dynamo_CPython3

Text input values from the command settings.

OUT

IronPython, Dynamo_CPython3

Result value to show after the script finishes. For predictable display, return text.

__doc__

IronPython

Active Revit Document.

__uidoc__

IronPython

Active Revit UIDocument.

__revit__, __uiapp__

IronPython

Active Revit application context.

__selection__

IronPython

Current Revit selection object.

Returning Output

The recommended way to show a result is to assign text to OUT.

In IronPython, print() output can also be shown when OUT is not set.

Example: Show the Active Document Name

Engine: IronPython

This example reads information only. It does not change the model.

Example: Use Input Values

Add one value to IN, for example a note or prefix, then run:

IN values are text strings.

Example: Change the Model Safely

Warning: This example starts a Revit transaction and can modify the active model. Use the same pattern only when you understand what the script changes.

BIMO does not automatically wrap your script in a transaction.

Where Scripts Are Stored

You can keep code directly in the Script setting, or store it in any .py file and select it in Script file.

BIMO does not copy .py files into a separate script library. If you use Script file, keep the file in a stable location that Revit can access.

Presets, Variants, and Keyboard Shortcuts

Run Python supports BIMO presets. A separate preset can store its own command settings:

  • Execution Engine;

  • Script or Script file;

  • IN values.

This is useful when you want to keep several Python workflows ready to run. For example:

Preset

What It Stores

Variant

Check Active View

A script that checks the active view.

Variant #1

Fill Parameters

A parameter-filling script and the required IN values.

Variant #2

Export Data

A path to a .py file that exports data.

Variant #3

After you assign a preset to Variant #1, Variant #2, or Variant #3, that variant appears in the dropdown under the Run Python button. Each variant is a separate Ribbon command item, so you can assign a shortcut to it in Revit Keyboard Shortcuts.

Recommended workflow:

  1. Create a separate preset for each Python workflow.

  2. Name the preset by action, for example Check Active View or Export Rooms.

  3. Assign frequently used presets to Variant #1..#3.

  4. Assign keyboard shortcuts to the required variant items in Revit.

Warning: a shortcut launches the selected variant immediately. If the script changes the model, first check the preset, the active document, and the script on a copy of the project.

For variant setup details, see Presets and Variants.

Errors and Troubleshooting

Problem

What To Check

The file cannot be read

Check the Script file path and file access.

The result does not appear

Return text through OUT, or use print() in IronPython. Empty output is not shown.

The script fails

BIMO shows error details and lets you copy them. Review the script and try again.

Dynamo_CPython3 does not run

Close the Dynamo UI if it is open, or use IronPython for scripts that need BIMO Revit variables.

Known Limitations

  • Script has priority over Script file.

  • IN values are passed as text strings.

  • BIMO does not create a transaction around your Python code.

  • Revit variables such as __doc__ and __uidoc__ are available only in IronPython.

  • For predictable result display, return text through OUT.

  • For fast keyboard access, use variants assigned to presets.

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