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_CPython3does 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.
OUT = "Document: " + __doc__.Title
In IronPython, print() output can also be shown when OUT is not set.
Example: Show the Active Document Name
Engine: IronPython
OUT = "Active document: " + __doc__.Title
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:
prefix = IN[0] if len(IN) > 0 else "Document"
OUT = prefix + ": " + __doc__.Title
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.
from Autodesk.Revit.DB import Transaction
doc = __doc__
transaction = Transaction(doc, "BIMO Python Script")
transaction.Start()
# Make model changes here.
transaction.Commit()
OUT = "Transaction completed"
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;ScriptorScript file;INvalues.
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.
In BIMO Toolbar 0.50 and later, the Ribbon item displays the assigned preset name. Choose + Assign preset… in a free slot to assign an existing unassigned preset. Confirming the assignment does not run the script. A shortcut to a free slot opens the same assignment workflow.
Recommended workflow:
- Create a separate preset for each Python workflow.
- Name the preset by action, for example
Check Active VieworExport Rooms. - Assign frequently used presets to
Variant #1..#3. - Assign keyboard shortcuts to the required variant items in Revit.
Warning: a shortcut for an assigned variant launches its preset immediately if the settings are valid. 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
Scripthas priority overScript file.INvalues 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 inIronPython. - For predictable result display, return text through
OUT. - For fast keyboard access, use variants assigned to presets.