Skip to main content
Never catch ALL exceptions!
Source Link
CodeManX
  • 29.7k
  • 3
  • 92
  • 131

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!")

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:
       print("COOL ADDON NOT INSTALLED!")

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!")
added 340 characters in body
Source Link
zeffii
  • 39.9k
  • 9
  • 106
  • 189

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:

>>> 'coolAddon' inclass dirAutoVTX(bpy.opstypes.view3dOperator):
True    bl_idname = 'view3d.autovtx'
    bl_label = 'autoVTX'

    (....)

edit 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:
       print("COOL ADDON NOT INSTALLED!")

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.

>>> 'coolAddon' in dir(bpy.ops.view3d)
True

edit

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:
       print("COOL ADDON NOT INSTALLED!")

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:
       print("COOL ADDON NOT INSTALLED!")
added 340 characters in body
Source Link
zeffii
  • 39.9k
  • 9
  • 106
  • 189

it canKnowing where the addon should be as simple asfound 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.

>>> 'coolAddon' in dir(bpy.ops.view3d)
True

soedit

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.

if 'coolAddon' indef dirdoCoolThing(bpy.ops.view3d):
   try:
       bpy.ops.view3d.coolAddon.foo()
else   except:
       print("COOL ADDON NOT INSTALLED!")

it can be as simple as

>>> 'coolAddon' in dir(bpy.ops.view3d)
True

so

if 'coolAddon' in dir(bpy.ops.view3d):
    bpy.ops.view3d.coolAddon.foo()
else:
    print("COOL ADDON NOT INSTALLED!")

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.

>>> 'coolAddon' in dir(bpy.ops.view3d)
True

edit

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:
       print("COOL ADDON NOT INSTALLED!")
Source Link
zeffii
  • 39.9k
  • 9
  • 106
  • 189
Loading