3
$\begingroup$

I'm developing an addon, and originally I made it as a single file.

When it was like that, I could simply execute "Reload scripts" in Blender to reload the changes I did to the script.

But after separating it into a package, I noticed the "reload scripts" dont work anymore, it doesn't show new changes. I need to close Blender and load the file again to see the changes. Is not that the script has a problem or anything. After re-executing blender again, the changes I made (like simple prints()) show.

But is a bit... clumsy, having to quit and reload over and over.

Do you know how can I reload my addon without quiting blender?

(I also tried disabling and enabling it from addons, but dont work)

$\endgroup$
12
  • 2
    $\begingroup$ Hello. I can't recommend enough this how to for developping using an external IDE b3d.interplanety.org/en/… It automatically updates your addon when you save the text file (you do have to enable it in the plugin settings) $\endgroup$
    – Gorgious
    Commented Jul 3, 2023 at 19:08
  • 1
    $\begingroup$ If you have subfolders, you should add a file called __init__.py in every folder. The file contents can be empty (no text), but the file should be there. Last I checked it was still usable for newer version, autocomplete is not mandatory for it to work, but it's helpful. IIRC there are recent versions on the autocomplete github $\endgroup$
    – Gorgious
    Commented Jul 4, 2023 at 17:33
  • 1
    $\begingroup$ I'm using VS Code for an IDE. This is the easiest way I've found to install the autocomplete: you can get the most up to date autocomplete files at: github.com/nutti/fake-bpy-module On the right hand side of that page where it says Releases, click the Latest button. You can get a zip file for the Blender version you want. You don't have to use pip, or any of the other methods to install it. The "Korchy" Github files link from the ".b3d, etc." page @Gorgious mentioned come from the "nutti" page. Continued... $\endgroup$
    – curious_1
    Commented Jul 5, 2023 at 1:57
  • 1
    $\begingroup$ The files on the "nutti" page I refer to can be used by creating a folder, unzip the file in that folder and follow the instructions regarding setting up the settings JSON file on the "b3d" page Gorgious mentioned. It has been a long time, so I might be wrong, but I seem to remember that if the multi file addon you are working on is what you have installed in Blender, that what Gorgious says in the first comment works. $\endgroup$
    – curious_1
    Commented Jul 5, 2023 at 1:58
  • 1
    $\begingroup$ "does the autocomplete help with reloading the addon?" No. And, after a quick test with the multi file addon I was thinking of, which has all the files in one folder, nothing new appeared after making some changes and reloading it. I must have been remembering a single file addon when I said I thought that reload worked. Unfortunately, I don't know of any tutorial, etc., that mentions reload for a multi file addon, or one using multiple folders. $\endgroup$
    – curious_1
    Commented Jul 6, 2023 at 7:01

1 Answer 1

4
$\begingroup$

Solution I've found

It is a Python thing. Once a module is imported, the interpreter won't automatically reload the changes.

So, when we reload the scripts in Blender (using operator "Reload Scripts"), Blender is only "truly reloading" the init.py files of the addons. But not the rest of the modules. We have to handle by ourselves.

Here is how (original source):

# (In your __init__.py)
# When bpy is already in local, we know this is not the initial import...
if "bpy" in locals():
    # ...so we need to reload our submodule(s) using importlib
    import importlib
    if "my_submodule" in locals():
        importlib.reload(my_submodule)


# This is only relevant on first run, on later reloads those modules
# are already in locals() and those statements do not do anything.
import bpy
import my_submodule

This way, the "Reload Scripts" will work as normal with multiple-files addons.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .