ImportError: No module named wpf (in Revit environment only) - User interface

2.1k views Asked by At

I'm able to make a simple working UI on VS launched with ipy interpreter but when I try to launch it in Revit environment (revit python shell or macro), I got the following error : ImportError: No module named wpf

wpf is a built-in module, so I don't think I forgot any reference or pythonpath.

I checked both sys.version (idea from a post on stackoverflow): import sys print sys.version

and got the same result on revitpythonshell and Ironpython console : 2.7.4 (IronPython 2.7.4 (2.7.0.40) on .NET 4.0.30319.18444 (64-bit)) un2.7.4 (IronPython 2.7.4 (2.7.0.40) on .NET 4.0.30319.18444 (64-bit))

Any idea ?

1

There are 1 answers

2
Daren Thomas On BEST ANSWER

I wonder... could it have to do with the search paths? I tried doing this in the ironpython console:

import wpf
wpf.__file__

but got no result, so I checked the filesystem for some other places the module could come from. So I did this:

  • Add a search path to: "C:\Program Files (x86)\IronPython 2.7\Platforms\Net40" (or wherever that is on your system)
  • Then do:

    import clr clr.AddReference('IronPython.Wpf') import wpf

On my machine that works. Of course this means you need to install IronPython on your system - RevitPythonShell ships with an IronPython version, but just includes the main dlls.