Unable to find custom Blender operator in F3 operator search (Blender 2.9)

Viewed 2657

I am working through this tutorial:
https://docs.blender.org/manual/en/latest/advanced/scripting/addon_tutorial.html

I have copied the script below from the tutorial and it compiles without any errors when I run the script. I should be able to search "Move X by One" in the operator search menu (F3) to execute the operator, but it does not show up in the operator search menu. How can I get the operator to show up in the search menu? Has something changed in blender 2.9?

bl_info = {
    "name": "Move X Axis",
    "category": "Object"
}

import bpy

class ObjectMoveX(bpy.types.Operator):
    bl_idname = "object.move_x"
    bl_label = "Move X by One"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        scene = context.scene
        for obj in scene.objects:
            obj.location.x += 1.0

        return {'FINISHED'}

def register():
    bpy.utils.register_class(ObjectMoveX)

def unregister():
    bpy.utils.unregister_class(ObjectMoveX)

if __name__ == "__main__":
    register()
4 Answers

Blender 2.90.1

As pointed out by other users, the API has been updated. You can see the release notes here:
Blender 2.90: Python API where it says:

...add-ons that expose operators only through search need to be updated.

This is due to the new addition of the operator search that only searches through menus (accessed by F3). Because of this, you need to add the operator to a menu.

Add the menu_func function:

def menu_func(self, context):
    self.layout.operator(ObjectMoveX.bl_idname)

And update the register function:

def register():
    bpy.utils.register_class(ObjectMoveX)
    bpy.types.VIEW3D_MT_object.append(menu_func)

You can now either access your operator via the operator search (F3) or through the menus, i.e. Object>YourOperatorName

If you do not want these to be accessible via these menus, the release notes also mention:

For more obscure operators that are for example intended mainly for developers, we recommend adding them in the TOPBAR_MT_app_system menu. This is accessible through the System menu under the Blender icon in the top bar.

You must enable the checkbox Developer Extras under Preferences -> Interface, and then maybe reload the addon. You probably had this figured out in the past, but lost the setting when upgrading.

Sybren aknowledged this in this post. The solution in my case was to copy this example. Here how it works:

  1. Add this after your call to register_class(): bpy.types.TOPBAR_MT_app_system.append(menu_func)
  2. Add the menu_func(self, context) with: self.layout.operator( your argument to register_class .bl_idname)

I had the same issue with 2.90.0, but when I upgraded to 2.90.1 it works perfectly. Just tested this with the code from your question. So I recommend you to try 2.90.1. For me it was updated silently with my system updates. If you want to do it manually, you can download it here: https://download.blender.org/release/Blender2.90/

(I cannot write a comment since I don't have enough stack overflow points)

Related