5

A recent question / answer involves what looks like an overridden operator:

bpy.ops.object.align()

Differing from the documented default, how do we find which addon(s) have registered the operator.

Method 1:

Edit to match operator id.

op_name = "import_scene.obj"

Script:

import addon_utils
from bpy.types import Operator
from importlib import import_module
import inspect

op_name = "import_scene.obj"

for m in addon_utils.modules(): name = m.name default, loaded = addon_utils.check(name) if loaded: mod = import_module(name) classes = getattr(mod, "classes", []) for c in classes: if ( issubclass(c, Operator) and
getattr(c, "bl_idname", "").startswith(op_name) ): print(name)

    if not classes:
        for k in dir(mod):
            cls = getattr(mod, k, None)
            if inspect.isclass(cls) and issubclass(cls, Operator):
                id = getattr(cls, "bl_idname", "")
                if id.startswith(op_name):
                    print(name)

By either looking at the addons classes or inspecting all objects of enabled addons. How do I run an existing add-on via the python API?

Method 2:

This approach disable, check op is still registered, re-enable...

Edit your operator of interest into

op_id = bpy.ops.import_scene.obj.idname()

Script:

import addon_utils
import bpy

op_id = bpy.ops.import_scene.obj.idname()

for m in addon_utils.modules(): name = m.name default, loaded = addon_utils.check(name) if loaded: addon_utils.disable(name) if not hasattr(bpy.types, op_id): print(name) #addon_utils.enable(name) #break addon_utils.enable(name)

How would you approach finding an operators registering addon(s) from its id name?.

Note: don't save preferences after running this, as addon preferences could be lost after disable.

aidan-j-rhoden
  • 186
  • 1
  • 10
batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • for me, on script 1: line 15: AttributeError: 'tuple' object has no attribute 'startswith' – james_t Mar 23 '21 at 15:18
  • 1
    Have put in fix for that, prob could flag it since it is "usual practice" to have a tuple for a "bl_idname" – batFINGER Mar 23 '21 at 15:31
  • super! thanks, unfortunately op_name = "bpy.ops.object.align" returns nothing for me, nor does op_name = "bpy" ! – james_t Mar 23 '21 at 16:10
  • ah i changed to op_name in getattr(c, "bl_idname", "") and now op_name = "align" returned "space_view3d_align_tools", so this is getting me what I need to know. Perhaps I would disable this add-on to help solve my problem. thanks again!!! – james_t Mar 23 '21 at 16:18

0 Answers0