My add-on edits Blender's UI scripts.
To apply changes to UI - edited scripts should be reloaded.
For this purpose I use bpy.ops.script.reload()
It does the job, but it works kind of slow.
So I wonder: is there any way to reload one specific UI script ?
I thought importlib
could do the thing, but appears it cannot...
An illustration:
As a simple example let's edit the script which is responsible for [File] menu tab.
It's space_topbar.py
, which is located in :
Blender\4.1\scripts\startup\bl_ui\space_topbar.py
For demonstration purposes let's get rid of a [Revert] menu option.
This option is being drawn inside the class TOPBAR_MT_file(Menu)
*in the line 282:
layout.operator("wm.revert_mainfile")
so let's just comment this line :
# layout.operator("wm.revert_mainfile")
*(After saving "space_topbar.py") I'm trying to reload the changed space_topbar
module:
1st try:
import sys,importlib
importlib.reload(sys.modules['bl_ui.space_topbar'])
2nd try:
*let's also reload the module's __init__
:
import sys,importlib
importlib.reload(sys.modules['bl_ui.space_topbar'])
importlib.reload(sys.modules['bl_ui'])
3rd try: *screw it – let's reload ALL modules which can be reloaded:
import sys,importlib
for m in list(sys.modules):
try:
importlib.reload(sys.modules[m])
except: pass
Ok, let's use Reload Scripts
:
import bpy
bpy.ops.script.reload()
• In this case the work is done:
• But "Reload Scripts" is SLOW.
So I wonder: is there any way to cherry-pick the UI script I would like to reload?
I thought Reload Scripts
just do bulk importlib.reload
, hence I could have use importlib
– but as we saw in the examples above – importlib.reload
is useless for reloading UI scripts.
➤ Is it possible to reload one specific UI-script without using Reload Scripts
?
?