CPython Key Error importing pyRevit module

This is my first attempt at a CPython script and I am having issues using the pyRevit module. here is my code:

#!python3

from pyrevit import DB, revit

collector = DB.FilteredElementCollector(revit.doc).OfCategory(DB.BuiltInCategory.OST_Areas).ToElements()
print (len(collector))

When i run it in Revit, I get the following error:

CPython Traceback:
KeyNotFoundException : KeyError
 at IronPython.Runtime.PythonDictionary.GetItem(Object key)
 at IronPython.Runtime.PythonDictionary.get_Item(Object[] key)

It definitely seems to have to do with importing pyRevit. I tried running the “Test CPython Command” in Dev tools, and it printed out everything up until the point where it imports pyRevit, and then throws the same error:

1 Like

i’m having the same issue.

Can’t really figure it out since i’m to novice in this kind of code.

Hey guys!

To start things off, I’m recent on using cypthon (and even pyRevit itself) but anyways, i’ll try to help out.
So first things first, Cpython is limited to what Ironpython can do from what concerns built-in functions from pyRevit. (somebody correct me if I’m wrong).

To call in Cypthon, this should do the trick with an example of getting levels;

from Autodesk.Revit.DB import * #Import Everything from DB (Good for beginners and development)
doc   = __revit__.ActiveUIDocument.Document

collector_lvl = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()

Best of luck !

well i’m looking for a replacement on the .forms module.

This are easto use for file selection and other GUi’s.
I could make them with tkinter but that doesn’t work with Cpython:
Tkinter module not found - Tools - pyRevit Forums (pyrevitlabs.io)