Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

blender

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()
like image 794
898Matthew Avatar asked Sep 12 '20 18:09

898Matthew


People also ask

How do I find the operator search in Blender?

A pop-up menu with access to all Blender tools is available by pressing F3 . Simply start typing the name of the tool you want to refine the list. When the list is sufficiently narrowed, LMB on the desired tool or navigate with Down and Up , activate it by pressing Return .

What is Blender operator?

A blender operator is primarily in charge of operating and adjusting blending machines while adhering to guidelines and safety protocols.


Video Answer


2 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.

like image 105
gmdev Avatar answered Sep 21 '22 04:09

gmdev


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)
like image 28
alef Avatar answered Sep 23 '22 04:09

alef