'NoneType' object has no attribute 'VersionNumber'

Hi everyone,
After updating to pyRevit 5.3.1, and occasionally when switching between different Revit versions, we’ve started getting the following error:

‘NoneType’ object has no attribute ‘VersionNumber’

It appears to be triggered by the hooks/doc-updater script.

The issue seems to originate from this file:

AppData\Roaming\pyRevit-Master\pyrevitlib\pyrevit\__init__.py

Further investigation (and a few additional related error messages) suggests that pyRevit is unable to find the app, possibly related to HOS_APP or a similar reference. The only reliable workaround so far has been to disable the doc-updater hook, which we’d prefer not to do.

The line in our doc-updater.py that triggers the issue is:

from pyrevit import EXEC_PARAMS, revit

Occasionally, we also get an error referring to the engine attribute:

IronPython Traceback:
Traceback (most recent call last):
File "X:\All 1 DATABASE\00_Python_Tools\All 1 Special.extension\hooks\doc-updater.py", line 4, in <module>
File "<string>", line 540, in _check_name_wrapper
File "C:\Users\ALL1-PC10\AppData\Roaming\pyRevit-Master\pyrevitlib\pyrevit\__init__.py", line 88, in <module>
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
AttributeError: 'module' object has no attribute 'engine'

I know this is a bit of an odd one, but any help, insight, or suggestions would be greatly appreciated—especially if there’s a way to keep the doc-updater enabled.

Thanks!

Ok, for now I have a working solution, though I’m not entirely sure why this happens.

It turns out there’s an issue with the revit module in pyRevit. The doc-updater hook only works if the revit module has been imported beforehand. For example, when we first run another hook (we tested with a DWG import hook) that includes:

from pyrevit import revit

then the doc-updater hook runs without any problems. It seems the revit module needs to be loaded first, though the reason isn’t clear.

As a workaround, we added an app-init.py hook that ensures the revit module is always loaded on application start. With this in place, the doc-updater hook works as expected.

This is just a workaround for now. If anyone knows why this happens or how it might be prevented in future pyRevit versions, your insights would be greatly appreciated.

1 Like

Your right, this looks like an initialization issue

I would try

def doc_updater_function():
    from pyrevit import EXEC_PARAMS, revit
    # your code here

doc_updater_function()

Or add a safety check:

try:
    from pyrevit import EXEC_PARAMS, revit
except AttributeError:
    pass