From da14a482f281e8d330ef5210ef22335a43eb726c Mon Sep 17 00:00:00 2001 From: Diptangshu Dey Date: Tue, 16 Nov 2021 10:45:23 +0100 Subject: Fix T90866: Python operator templates are not accessible from menus Python Operator templates made accessible from respective menus (required to also use F3 search for quick access) Also fixed Modal Draw Operator id_name (had duplicate name from other template) Maniphest Tasks: T90866 Differential Revision: https://developer.blender.org/D13182 --- doc/python_api/examples/bpy.types.Operator.1.py | 5 +++++ doc/python_api/examples/bpy.types.Operator.2.py | 2 +- doc/python_api/examples/bpy.types.Operator.3.py | 6 ++++++ doc/python_api/examples/bpy.types.Operator.4.py | 5 +++++ doc/python_api/examples/bpy.types.Operator.5.py | 5 +++++ doc/python_api/examples/bpy.types.Operator.6.py | 5 +++++ doc/python_api/examples/bpy.types.Operator.py | 5 +++++ 7 files changed, 32 insertions(+), 1 deletion(-) (limited to 'doc/python_api') diff --git a/doc/python_api/examples/bpy.types.Operator.1.py b/doc/python_api/examples/bpy.types.Operator.1.py index 728d36f24b9..84397574856 100644 --- a/doc/python_api/examples/bpy.types.Operator.1.py +++ b/doc/python_api/examples/bpy.types.Operator.1.py @@ -42,8 +42,13 @@ class SimpleMouseOperator(bpy.types.Operator): self.y = event.mouse_y return self.execute(context) +# Only needed if you want to add into a dynamic menu +def menu_func(self, context): + self.layout.operator(SimpleMouseOperator.bl_idname, text="Simple Mouse Operator") +# Register and add to the view menu (required to also use F3 search "Simple Mouse Operator" for quick access) bpy.utils.register_class(SimpleMouseOperator) +bpy.types.VIEW3D_MT_view.append(menu_func) # Test call to the newly defined operator. # Here we call the operator and invoke it, meaning that the settings are taken diff --git a/doc/python_api/examples/bpy.types.Operator.2.py b/doc/python_api/examples/bpy.types.Operator.2.py index 5ba09c7e380..7ab0143b925 100644 --- a/doc/python_api/examples/bpy.types.Operator.2.py +++ b/doc/python_api/examples/bpy.types.Operator.2.py @@ -43,7 +43,7 @@ def menu_func(self, context): self.layout.operator(ExportSomeData.bl_idname, text="Text Export Operator") -# Register and add to the file selector +# Register and add to the file selector (required to also use F3 search "Text Export Operator" for quick access) bpy.utils.register_class(ExportSomeData) bpy.types.TOPBAR_MT_file_export.append(menu_func) diff --git a/doc/python_api/examples/bpy.types.Operator.3.py b/doc/python_api/examples/bpy.types.Operator.3.py index ef8bce3d8a9..9a12a7e3615 100644 --- a/doc/python_api/examples/bpy.types.Operator.3.py +++ b/doc/python_api/examples/bpy.types.Operator.3.py @@ -27,8 +27,14 @@ class DialogOperator(bpy.types.Operator): wm = context.window_manager return wm.invoke_props_dialog(self) +# Only needed if you want to add into a dynamic menu +def menu_func(self, context): + self.layout.operator(DialogOperator.bl_idname, text="Dialog Operator") + +# Register and add to the object menu (required to also use F3 search "Dialog Operator" for quick access) bpy.utils.register_class(DialogOperator) +bpy.types.VIEW3D_MT_object.append(menu_func) # Test call. bpy.ops.object.dialog_operator('INVOKE_DEFAULT') diff --git a/doc/python_api/examples/bpy.types.Operator.4.py b/doc/python_api/examples/bpy.types.Operator.4.py index 6b74a96eb2b..00c9cd250b1 100644 --- a/doc/python_api/examples/bpy.types.Operator.4.py +++ b/doc/python_api/examples/bpy.types.Operator.4.py @@ -41,8 +41,13 @@ class CustomDrawOperator(bpy.types.Operator): col.prop(self, "my_string") +# Only needed if you want to add into a dynamic menu +def menu_func(self, context): + self.layout.operator(CustomDrawOperator.bl_idname, text="Custom Draw Operator") +# Register and add to the object menu (required to also use F3 search "Custom Draw Operator" for quick access) bpy.utils.register_class(CustomDrawOperator) +bpy.types.VIEW3D_MT_object.append(menu_func) # test call bpy.ops.object.custom_draw('INVOKE_DEFAULT') diff --git a/doc/python_api/examples/bpy.types.Operator.5.py b/doc/python_api/examples/bpy.types.Operator.5.py index f1880a70018..a0b4a6d6841 100644 --- a/doc/python_api/examples/bpy.types.Operator.5.py +++ b/doc/python_api/examples/bpy.types.Operator.5.py @@ -55,8 +55,13 @@ class ModalOperator(bpy.types.Operator): context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} +# Only needed if you want to add into a dynamic menu +def menu_func(self, context): + self.layout.operator(ModalOperator.bl_idname, text="Modal Operator") +# Register and add to the object menu (required to also use F3 search "Modal Operator" for quick access) bpy.utils.register_class(ModalOperator) +bpy.types.VIEW3D_MT_object.append(menu_func) # test call bpy.ops.object.modal_operator('INVOKE_DEFAULT') diff --git a/doc/python_api/examples/bpy.types.Operator.6.py b/doc/python_api/examples/bpy.types.Operator.6.py index ff14bfa7197..20ee4c21446 100644 --- a/doc/python_api/examples/bpy.types.Operator.6.py +++ b/doc/python_api/examples/bpy.types.Operator.6.py @@ -31,8 +31,13 @@ class SearchEnumOperator(bpy.types.Operator): context.window_manager.invoke_search_popup(self) return {'RUNNING_MODAL'} +# Only needed if you want to add into a dynamic menu +def menu_func(self, context): + self.layout.operator(SearchEnumOperator.bl_idname, text="Search Enum Operator") +# Register and add to the object menu (required to also use F3 search "Search Enum Operator" for quick access) bpy.utils.register_class(SearchEnumOperator) +bpy.types.VIEW3D_MT_object.append(menu_func) # test call bpy.ops.object.search_enum_operator('INVOKE_DEFAULT') diff --git a/doc/python_api/examples/bpy.types.Operator.py b/doc/python_api/examples/bpy.types.Operator.py index c9bf169f73e..5299b198774 100644 --- a/doc/python_api/examples/bpy.types.Operator.py +++ b/doc/python_api/examples/bpy.types.Operator.py @@ -22,8 +22,13 @@ class HelloWorldOperator(bpy.types.Operator): print("Hello World") return {'FINISHED'} +# Only needed if you want to add into a dynamic menu +def menu_func(self, context): + self.layout.operator(HelloWorldOperator.bl_idname, text="Hello World Operator") +# Register and add to the view menu (required to also use F3 search "Hello World Operator" for quick access) bpy.utils.register_class(HelloWorldOperator) +bpy.types.VIEW3D_MT_view.append(menu_func) # test call to the newly defined operator bpy.ops.wm.hello_world() -- cgit v1.2.3