Can't make operator poll work nor make operator internal

I’m working on my Convert Rotation Mode addon to upgrade it to 4.2’s extensions platform. While submitting it to the extensions, I was pointed out that the operator still runs even when it shouldn’t be able to. Leading to errors and unfruitful operation.

So firstly, I made the operator’s button disabled as long as there’s no pose bone selected AND its dependency addon (Copy Global Transform) is disabled. It was as easy as updating the operator’s poll:

@classmethod
def poll(cls, context):
    return context.preferences.addons.find("copy_global_transform") != -1 and len(context.selected_pose_bones) > 0

It works as intended. BUT I can still run the operator from the operator search (F3).

So the poll works for the UI, but not for running the operator?

I tried changing the poll to be more verbose to see if somehow the conditions were met when running from F3:

@classmethod
def poll(cls, context):
    # return context.preferences.addons.find("copy_global_transform") != -1 and len(context.selected_pose_bones) > 0
    addon_available = context.preferences.addons.find("copy_global_transform") != -1
    bones_selected = len(context.selected_pose_bones) > 0
    print(f"Addon available: {addon_available}, Bones selected: {bones_selected}")
    return addon_available and bones_selected

But nope, even the console agrees that they aren’t, and yet it runs.

Addon available: False, Bones selected: False

So I tried a second method, make the operator unavailable to the Operator Search, which according to Operator(bpy_struct) — Blender Python API should be as easy as adding the bl_option ‘INTERNAL’:

class CRM_OT_convert_rotation_mode(Operator):
    bl_idname = "crm.convert_rotation_mode"
    bl_label = "Convert Rotation Mode"
    bl_description = "Convert the selected bone's rotation order on all keyframes."
    bl_options = {'UNDO', 'INTERNAL'}

But nope, it’s still available.

And finally, I tried brute-forcing it in the execute function:

def execute(self, context):
    if context.preferences.addons.find("copy_global_transform") == -1:
        self.report({'WARNING'}, "Please enable the 'Copy Global Transform' addon.")
        return {'CANCELLED'}

Still not better.

I’m completely lost here. I don’t understand why none of these solutions succeed.

I made a different branch for these issues if you want to see the whole things as it is now: L0Lock/convertRotationMode/tree/fix-%2342-and-%2343

Thanks for any help.

Turns out it was all working… The issue was that my addon isn’t the only one with a similar operator, and I was mistaking them as mine…

Lessons of the day:

  • Correctly name your operators with a name specific to your addon

  • Pay attention to the operators id names, mine all follow the bpy.ops.crm.something format, those from other addons are different:

    image
    Auto Rig Pro uses bpy.ops.arp.something so it’s easily identifiable, but the other two are from… an old addon that was integrated into rigify? :hushed:

  • Maybe give a different name to your operators. Mine is “Convert Rotation Mode”, singular. Not the most obvious but I added “MINE” during testing, to be sure…

Also go walk for a bit when you hit a wall, tunnel vision is real. That problem was dumb.