Reload required on script update?

Hi all, I remember I used to develop/debug pyRevit scripts and only having to save the changes I made in *.py files for it to update.

Recently, I notice I have to reload the complete UI on every change.

How is this behavior managed? Can I prevent having to reload the UI on every small change?

You don’t need to reload pyRevit if you make changes to common python scripts. Saving the script and run it again is should be enough as long as you didn’t make change in a module.

Reload is necessary when you make changes in the GUI (bundles, tooltip images, new buttons, icons etc…) or if new file is added (config, module etc.)

I have no information that anything has changed in this respect.

2 Likes

On another note, I believe most IDEs will automatically save files as you’re editing. I use PyCharm and I can change one line and then run it immediately with the updated code.

I was using pyRevit today and observed that making changes to a button’s script reflects live changes, but changes to an imported module requires reloading. For example, I have a Create Worksets button in script.py that calls a function in worksets.py. Changes to script.py are reflected immediately, but not changes to worksets.py. I think this is a Python issue, where worksets.py is cached by the Python engine. I tried following instructions from these two sites without success:

One of these ought to work, but I get errors for each.

from importlib import reload
import X
reload(X)
from X import Y

Error: System.MissingMemberException: 'NoneType' object has no attribute 'name'

import imp
imp.reload(module)

Error: System.MissingMemberException: 'NoneType' object has no attribute 'name'

1 Like

I found two solutions to this.

First, delete the module from sys.modules and reload:

import sys
def reload(module_name):
    # Delete the module from sys.modules
    if module_name in sys.modules:
        del sys.modules[module_name]
reload('target_module')
# now load the module
import target_module
# or something inside
from target_module import thing

Second (the better option in most cases), hold Ctrl + Shift + Alt while clicking the button to force the engine to reload. Button Click Modes: Reload Engine