1
$\begingroup$

I want to import an addon into a Blender script

Is this possible, are there any tutorials about it?

$\endgroup$
  • $\begingroup$ Something like from io_scene_3ds.import_3ds import load_3ds to use load_3ds(filepath, context, IMPORT_CONSTRAIN_BOUNDS=10.0, IMAGE_SEARCH=True, APPLY_MATRIX=True, global_matrix=None) code from the import 3ds addon? or do you want to enable the addon in a script? $\endgroup$ – batFINGER Jul 19 '16 at 18:37
  • $\begingroup$ i would like to enable to addon in a script @batFINGER $\endgroup$ – Alexander Pagan Jul 19 '16 at 18:38
5
$\begingroup$

There are addon utilities available in 2.77/scripts/modules/addon_utils.py which you can import into your script.

Here is an overkill example, lists all addons and then tries to enable addons named ['mesh_looptools','mocap_madness','goose']

import bpy
from addon_utils import check, paths, enable

def get_all_addons(display=False):
    """
    Prints the addon state based on the user preferences.
    """
    import sys
    paths_list = paths()
    addon_list = []
    for path in paths_list:
        bpy.utils._sys_path_ensure(path)
        for mod_name, mod_path in bpy.path.module_names(path):
            is_enabled, is_loaded = check(mod_name)
            addon_list.append(mod_name)
            if display:  #for example
                print("%s default:%s loaded:%s " % (mod_name, is_enabled, is_loaded))                
    return(addon_list)
#print all the addons and show if enabled and default
addons = get_all_addons(True)
#enable dependencies
addon_dependencies = ['mesh_looptools','MocapMadness','goose']
for addon in addon_dependencies:
    if addon in addons:
        is_enabled, is_loaded = check(addon)
        if not is_enabled:
            print("%s enabled" % addon)
            enable(addon)
    else:
        print("Error Dependency %s missing" % addon)

Answer from https://blenderartists.org/forum/showthread.php?234219-Check-if-Add-On-is-enabled-using-Python&p=1970462&viewfull=1#post1970462

Mainly only need

    is_enabled, is_loaded = check(addon)
    if not is_enabled:
        print("%s enabled" % addon)
        enable(addon)
| improve this answer | |
$\endgroup$
  • $\begingroup$ okay, so would i have to change addon to what the addon is called $\endgroup$ – Alexander Pagan Jul 19 '16 at 19:20
  • $\begingroup$ Yes, like "mesh_looptools" for Mesh Loop Tools $\endgroup$ – batFINGER Jul 19 '16 at 19:29
  • $\begingroup$ how would i use the addon after it was enabled $\endgroup$ – Alexander Pagan Jul 19 '16 at 19:34
  • 2
    $\begingroup$ Depends on the addon. Addon foo_bar may register an operator "foo_bar" which you would call using bpy.ops.foo.bar() $\endgroup$ – batFINGER Jul 19 '16 at 20:15
  • $\begingroup$ What im wanting to do is open a 3d view addon from python, ho would i do that $\endgroup$ – Alexander Pagan Jul 19 '16 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.