| name | pyrevit-ironpython |
| description | Write pyRevit IronPython tools for Revit with correct project structure, coding conventions, and WPF/MVVM patterns. Use when creating or editing pyRevit pushbutton scripts, shared libs, bundle.yaml, XAML views, or ViewModels. |
pyRevit IronPython Development
Critical Rules
- No wildcard imports —
from Autodesk.Revit import DB, never from Autodesk.Revit.DB import *
- No global state — never cache
HOST_APP.doc/HOST_APP.uidoc at module level; pass as parameters
- All Revit API calls inside methods — imports at top, but execution only inside functions/methods
engine.clean: true — enable during development for module reload; disable in release for cached performance
- Python 2/3 compatible —
"{}".format(x) not f-strings, ParentClass.__init__(self) not super()
- Type hints on everything — comment-style:
# type: (str, int) -> bool
- Clean code — no god files/methods/classes; split into
constants/models/services/viewmodels/views/utils
lib/ naming convention — extension-level lib/ for shared code, pushbutton-level lib/ for tool-specific code
Quick Reference
from Autodesk.Revit import DB
from pyrevit import HOST_APP
from pyrevit.compat import get_elementid_value_func
element_id_value = get_elementid_value_func()
def collect_schedules(doc):
return list(DB.FilteredElementCollector(doc).OfClass(DB.ViewSchedule).ToElements())
def main():
doc = HOST_APP.doc
schedules = collect_schedules(doc)
bundle.yaml
title: My Tool Name
context: doc-project
tooltip:
en_us: |
Version = 1.0
Description: ...
author: "Author.Name"
engine:
clean: true
Reference Files
| File | When to Read |
|---|
| Project Structure | Extension layout, bundle hierarchy, shared vs local lib, entry point pattern |
| Coding Conventions | Python 2/3 compat, import rules, type hints, transactions, error reporting |
| WPF & MVVM | ObservableBase, RelayCommand, WPFWindow, notifications, XAML templates |