Problem

I'm creating an addon loader that allows developers to test their addon in realtime from their external development environment (like eclipse and pydev). Since Blender does not reload all addons automaticly I have to deactivate and reactivate the addon (the refresh button does just update the addon list)

My Idea

I thought I could dig a bit in the Blender sourcecode and use the original code that activates and deactivates an addon. I found several things (in space_userpref.py line 1227 & line 1263) that could do what I want, but it never worked.

I need

the simplest way of de- and reactivating an addon with a known name.

• Sounds like: blender.stackexchange.com/a/32035/3710 ? – p2or Jun 13 '15 at 16:00
• This problem is very similar, But as far as I understood your stackexchange post this workflow is limited to single file-addons. I want to create an addon that can manage huge projects with submodules and multiple files and is capable of making backups and automaticly incrementing the version number. I know the process mentioned in [link](blender.stackexchange.com/a/32035/3710) , but this workflow distracts developers from coding. That's why I want to make the gap between external environment and Blender as small as possible by automating everything in between. – frameworker Jun 13 '15 at 16:09

1 Answer

There is an API to manage addons to bypass operators, see addon_utils, this isn't exposed in the API docs because its mainly to manage internal functions. But the API is quite stable now.

addon_utils.enable(
module_name, default_set=False, persistent=False, handle_error=None)

addon_utils.disable(
module_name, default_set=False, handle_error=None)


Typically its enough to call:

import addon_utils
addon_utils.enable("my_addon")
addon_utils.disable("my_addon")


Use default_set if you want the value to be stored in the preferences, (although these will have to be saved for the new configuration to be used on restarting Blender).

See the docstrings in the source:
https://developer.blender.org/diffusion/B/browse/master/release/scripts/modules/addon_utils.py

Since you ask about reloading, see this question on recursive reloading.

https://stackoverflow.com/questions/28101895/reloading-packages-and-their-submodules-recursively-in-python