Could not add references to assembly IronPython.Wpf

My script used to be ok with wpf but now suddenly has error

you will need to provide a tad more details: QuickStart in the Realm of pyRevit and the Revit API

IronPython Traceback:
Traceback (most recent call last):
File “C:\Users\Wilson-WS.Lam\AppData\Roaming\pyRevit\Extensions\MEP.extension\MEP.tab\Family to Room.panel\Export Rooms.pushbutton\Export Rooms_script.py”, line 18, in
File “wpf.py”, line 14, in
ImportError: No module named _wpf

and with the code?

basic guidelines for the forum are provided in the link in my first post and look like this:

  1. Search First: Before posting a new question, take a moment to search the forum. Someone might have already encountered a similar issue and found a solution.
  2. Provide Details: When asking for help, be sure to include your code and configuration settings. Generic descriptions or error messages aren’t enough for us to pinpoint the problem accurately.
  3. Use Code Blocks: When sharing code snippets or file contents, wrap them in triple backticks (```) to maintain formatting and readability.
  4. Mark Solutions: If someone provides a solution that solves your problem, please mark their message as the solution. This helps others quickly identify what worked.

There was a change with the 5.0 update regarding WPF, if I remember correctly. We had the same/similar issues when upgrading from 4.8 to 5.0. Some of our custom forms needed a fix in out code.

Don’t remember the fix right now, will try to check if I can find it tomorrow.

Also, WPF forms is not working in some older versions of Revit (within pyRevit). At least R2020 has a bug that I know of.

thanks! I already asked chatGPT to change it to window form :grinning:

I think the fix was:

from pyrevit import forms
import wpf
from System.Windows import Application, Window

I’m sure others could correct/confirm this.

I have had a similar error when trying to import pyRevit in RevitPythonShell in Revit 2023. It works fine in 2025, and my scripts/buttons work in pyRevit.

I had thought the problem was in pyrevit.engine, (line 83 of __init__.py tries to import pyrevit.engine as eng and fails):

>>> import pyrevit.engine
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 540, in _check_name_wrapper
  File "<string>", line 1565, in load_module
  File "<string>", line 597, in _load_module_shim
  File "<string>", line 1208, in load
  File "<string>", line 1188, in _load_unlocked
  File "<string>", line 1117, in _exec
  File "<string>", line 1459, in exec_module
  File "<string>", line 322, in _call_with_frames_removed
  File "C:\Users\s.williams\AppData\Roaming\pyRevit-Master\pyrevitlib\pyrevit\__init__.py", line 83, in <module>
AttributeError: 'module' object has no attribute 'engine'

However, pasting the contents of engine.py into RPS works.

I started pasting the code from __init__.py into RPS, and it has an error in compat.py on the line __builtins__["unicode"] = str:

>>> 
Traceback (most recent call last):
  File "<string>", line 25, in <module>
TypeError: 'module' object is not subscriptable

There must have been something in the the switch to .NET 8 for Revit 2025, either in pyRevit or RevitPythonShell. Everything worked fine in v4.8.16.24121 except pyrevit.forms.