Skip to main content
Notice removed Draw attention by Yaroslav
Bounty Ended with unwave's answer chosen by Yaroslav
Notice added Draw attention by Yaroslav
Bounty Started worth 100 reputation by Yaroslav
added 1 character in body
Source Link
Yaroslav
  • 312
  • 4
  • 15

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'])

• no effect: img_01


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'])

• no effect: img_02


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

• no effect: img_03


Ok, let's use Reload Scripts:

import bpy
bpy.ops.script.reload()

• In this case the work is done: img_04



• But "Reload Scripts" is SLOW.

So I wonder: is werethere any way to cherycherry-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 ?

?

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'])

• no effect: img_01


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'])

• no effect: img_02


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

• no effect: img_03


Ok, let's use Reload Scripts:

import bpy
bpy.ops.script.reload()

• In this case the work is done: img_04



• But "Reload Scripts" is SLOW.

So I wonder: is were any way to chery-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 ?

?

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'])

• no effect: img_01


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'])

• no effect: img_02


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

• no effect: img_03


Ok, let's use Reload Scripts:

import bpy
bpy.ops.script.reload()

• In this case the work is done: img_04



• 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 ?

?

Source Link
Yaroslav
  • 312
  • 4
  • 15

How to reload ONE particular UI script? (an alternative to 'Reload Scripts' )

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'])

• no effect: img_01


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'])

• no effect: img_02


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

• no effect: img_03


Ok, let's use Reload Scripts:

import bpy
bpy.ops.script.reload()

• In this case the work is done: img_04



• But "Reload Scripts" is SLOW.

So I wonder: is were any way to chery-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 ?

?