6
$\begingroup$

How can I check to see if an operator from another addon is installed from my addon? This my current attempt.

def doCoolThing():
   try:
           bpy.ops.coolAddon.foo()
    except AttributeError:
           print("COOL ADDON NOT INSTALLED!")
$\endgroup$
4
$\begingroup$

Knowing where the addon should be found is the first thing to sort out. You can either look at the addon source and see where it attaches to, or investigate by hand. Generally you'll find it in the bl_idname of the Operator.

For example I have an addon called autoVTX for which the Operator code has these lines at the top:

class AutoVTX(bpy.types.Operator):
    bl_idname = 'view3d.autovtx'
    bl_label = 'autoVTX'

    # ...

This Operator can be accessed from bpy.ops.view3d.autovtx()

The try/except route is fine btw, as CoDEmanX rightfully points out in the comment. If you know where an addon or operator should be when installed then this should work.

def doCoolThing():
   try:
       bpy.ops.view3d.coolAddon.foo()
   except AttributeError:
       print("COOL ADDON NOT INSTALLED!")
$\endgroup$
2
$\begingroup$

Another way is to look up the type:

if hasattr(bpy.types, "IMPORT_SCENE_OT_obj"): ...

You can locate the script like this by the way:

>>> sys.modules[bpy.types.IMPORT_SCENE_OT_obj.__module__].__file__
'C:\\Program Files\\Blender Foundation\\Blender\\2.70\\scripts\\addons\\io_scene_obj\\__init__.py'
$\endgroup$
  • $\begingroup$ where does hasattr live? $\endgroup$ – Ben L Apr 21 '14 at 13:49
  • $\begingroup$ it's a built-in language feature, if that's your question $\endgroup$ – CoDEmanX Apr 21 '14 at 17:30

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.