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.
op_name = "bpy.ops.object.align"
returns nothing for me, nor doesop_name = "bpy"
! $\endgroup$op_name in getattr(c, "bl_idname", "")
and nowop_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!!! $\endgroup$