Not sure why Reload Scripts
didn't work at first for me, maybe I didn't save the correct file or whatnot, anyway, that's a possible way. My issues were however with this method is that
- I have to edit files in Blender addons folder, not in my project folder;
- this reloads all the scripts, on my machine with a lot of addons installed it takes about four seconds and plus after that some addons reset their settings;
In the end I followed this article for creating and debugging multifile addons. Author suggests using a specific setup for the __init__.py
file and then provides a Blender script in the second part of the article to update only a specific addon. I've assigned this script to a hotkey and it works much faster than reloading all the scripts.
Here are the final scripts from the article. __init__.py
:
bl_info = {
'name': 'Test Multifile Addon',
'category': 'All',
'version': (0, 0, 1),
'blender': (2, 80, 0)
}
modulesNames = ['addCube', 'addCubePanel'] # a list of imported module names
import sys
import importlib
modulesFullNames = {}
for currentModuleName in modulesNames:
if 'DEBUG_MODE' in sys.argv:
modulesFullNames[currentModuleName] = ('{}'.format(currentModuleName))
else:
modulesFullNames[currentModuleName] = ('{}.{}'.format(__name__, currentModuleName))
for currentModuleFullName in modulesFullNames.values():
if currentModuleFullName in sys.modules:
importlib.reload(sys.modules[currentModuleFullName])
else:
globals()[currentModuleFullName] = importlib.import_module(currentModuleFullName)
setattr(globals()[currentModuleFullName], 'modulesNames', modulesFullNames)
def register():
for currentModuleName in modulesFullNames.values():
if currentModuleName in sys.modules:
if hasattr(sys.modules[currentModuleName], 'register'):
sys.modules[currentModuleName].register()
def unregister():
for currentModuleName in modulesFullNames.values():
if currentModuleName in sys.modules:
if hasattr(sys.modules[currentModuleName], 'unregister'):
sys.modules[currentModuleName].unregister()
if __name__ == "__main__":
register()
Blender script to reload the addon:
import os
import sys
filesDir = "d:/Python/TestMultifile"
initFile = "__init__.py"
if filesDir not in sys.path:
sys.path.append(filesDir)
file = os.path.join(filesDir, initFile)
if 'DEBUG_MODE' not in sys.argv:
sys.argv.append('DEBUG_MODE')
exec(compile(open(file).read(), initFile, 'exec'))
if 'DEBUG_MODE' in sys.argv:
sys.argv.remove('DEBUG_MODE')