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
This commit is contained in:
@@ -42,8 +42,13 @@ class SimpleMouseOperator(bpy.types.Operator):
|
|||||||
self.y = event.mouse_y
|
self.y = event.mouse_y
|
||||||
return self.execute(context)
|
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.utils.register_class(SimpleMouseOperator)
|
||||||
|
bpy.types.VIEW3D_MT_view.append(menu_func)
|
||||||
|
|
||||||
# Test call to the newly defined operator.
|
# Test call to the newly defined operator.
|
||||||
# Here we call the operator and invoke it, meaning that the settings are taken
|
# Here we call the operator and invoke it, meaning that the settings are taken
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ def menu_func(self, context):
|
|||||||
self.layout.operator(ExportSomeData.bl_idname, text="Text Export Operator")
|
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.utils.register_class(ExportSomeData)
|
||||||
bpy.types.TOPBAR_MT_file_export.append(menu_func)
|
bpy.types.TOPBAR_MT_file_export.append(menu_func)
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,14 @@ class DialogOperator(bpy.types.Operator):
|
|||||||
wm = context.window_manager
|
wm = context.window_manager
|
||||||
return wm.invoke_props_dialog(self)
|
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.utils.register_class(DialogOperator)
|
||||||
|
bpy.types.VIEW3D_MT_object.append(menu_func)
|
||||||
|
|
||||||
# Test call.
|
# Test call.
|
||||||
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
|
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
|
||||||
|
|||||||
@@ -41,8 +41,13 @@ class CustomDrawOperator(bpy.types.Operator):
|
|||||||
|
|
||||||
col.prop(self, "my_string")
|
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.utils.register_class(CustomDrawOperator)
|
||||||
|
bpy.types.VIEW3D_MT_object.append(menu_func)
|
||||||
|
|
||||||
# test call
|
# test call
|
||||||
bpy.ops.object.custom_draw('INVOKE_DEFAULT')
|
bpy.ops.object.custom_draw('INVOKE_DEFAULT')
|
||||||
|
|||||||
@@ -55,8 +55,13 @@ class ModalOperator(bpy.types.Operator):
|
|||||||
context.window_manager.modal_handler_add(self)
|
context.window_manager.modal_handler_add(self)
|
||||||
return {'RUNNING_MODAL'}
|
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.utils.register_class(ModalOperator)
|
||||||
|
bpy.types.VIEW3D_MT_object.append(menu_func)
|
||||||
|
|
||||||
# test call
|
# test call
|
||||||
bpy.ops.object.modal_operator('INVOKE_DEFAULT')
|
bpy.ops.object.modal_operator('INVOKE_DEFAULT')
|
||||||
|
|||||||
@@ -31,8 +31,13 @@ class SearchEnumOperator(bpy.types.Operator):
|
|||||||
context.window_manager.invoke_search_popup(self)
|
context.window_manager.invoke_search_popup(self)
|
||||||
return {'RUNNING_MODAL'}
|
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.utils.register_class(SearchEnumOperator)
|
||||||
|
bpy.types.VIEW3D_MT_object.append(menu_func)
|
||||||
|
|
||||||
# test call
|
# test call
|
||||||
bpy.ops.object.search_enum_operator('INVOKE_DEFAULT')
|
bpy.ops.object.search_enum_operator('INVOKE_DEFAULT')
|
||||||
|
|||||||
@@ -22,8 +22,13 @@ class HelloWorldOperator(bpy.types.Operator):
|
|||||||
print("Hello World")
|
print("Hello World")
|
||||||
return {'FINISHED'}
|
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.utils.register_class(HelloWorldOperator)
|
||||||
|
bpy.types.VIEW3D_MT_view.append(menu_func)
|
||||||
|
|
||||||
# test call to the newly defined operator
|
# test call to the newly defined operator
|
||||||
bpy.ops.wm.hello_world()
|
bpy.ops.wm.hello_world()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class ExportSomeData(Operator, ExportHelper):
|
|||||||
def menu_func_export(self, context):
|
def menu_func_export(self, context):
|
||||||
self.layout.operator(ExportSomeData.bl_idname, text="Text Export Operator")
|
self.layout.operator(ExportSomeData.bl_idname, text="Text Export Operator")
|
||||||
|
|
||||||
|
# Register and add to the "file selector" menu (required to use F3 search "Text Export Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(ExportSomeData)
|
bpy.utils.register_class(ExportSomeData)
|
||||||
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
|
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class ImportSomeData(Operator, ImportHelper):
|
|||||||
def menu_func_import(self, context):
|
def menu_func_import(self, context):
|
||||||
self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator")
|
self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator")
|
||||||
|
|
||||||
|
# Register and add to the "file selector" menu (required to use F3 search "Text Import Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(ImportSomeData)
|
bpy.utils.register_class(ImportSomeData)
|
||||||
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
|
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class AddBox(bpy.types.Operator, AddObjectHelper):
|
|||||||
def menu_func(self, context):
|
def menu_func(self, context):
|
||||||
self.layout.operator(AddBox.bl_idname, icon='MESH_CUBE')
|
self.layout.operator(AddBox.bl_idname, icon='MESH_CUBE')
|
||||||
|
|
||||||
|
# Register and add to the "add mesh" menu (required to use F3 search "Add Box" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(AddBox)
|
bpy.utils.register_class(AddBox)
|
||||||
bpy.types.VIEW3D_MT_mesh_add.append(menu_func)
|
bpy.types.VIEW3D_MT_mesh_add.append(menu_func)
|
||||||
|
|||||||
@@ -33,13 +33,18 @@ class UvOperator(bpy.types.Operator):
|
|||||||
main(context)
|
main(context)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
def menu_func(self, context):
|
||||||
|
self.layout.operator(UvOperator.bl_idname, text = "Simple UV Operator")
|
||||||
|
|
||||||
|
# Register and add to the "UV" menu (required to also use F3 search "Simple UV Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(UvOperator)
|
bpy.utils.register_class(UvOperator)
|
||||||
|
bpy.types.IMAGE_MT_uvs.append(menu_func)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(UvOperator)
|
bpy.utils.unregister_class(UvOperator)
|
||||||
|
bpy.types.IMAGE_MT_uvs.remove(menu_func)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -35,13 +35,18 @@ class ModalOperator(bpy.types.Operator):
|
|||||||
self.report({'WARNING'}, "No active object, could not finish")
|
self.report({'WARNING'}, "No active object, could not finish")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
def menu_func(self, context):
|
||||||
|
self.layout.operator(ModalOperator.bl_idname, text=ModalOperator.bl_label)
|
||||||
|
|
||||||
|
# Register and add to the "view" menu (required to also use F3 search "Simple Modal Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(ModalOperator)
|
bpy.utils.register_class(ModalOperator)
|
||||||
|
bpy.types.VIEW3D_MT_object.append(menu_func)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(ModalOperator)
|
bpy.utils.unregister_class(ModalOperator)
|
||||||
|
bpy.types.VIEW3D_MT_object.remove(menu_func)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ def draw_callback_px(self, context):
|
|||||||
|
|
||||||
class ModalDrawOperator(bpy.types.Operator):
|
class ModalDrawOperator(bpy.types.Operator):
|
||||||
"""Draw a line with the mouse"""
|
"""Draw a line with the mouse"""
|
||||||
bl_idname = "view3d.modal_operator"
|
bl_idname = "view3d.modal_draw_operator"
|
||||||
bl_label = "Simple Modal View3D Operator"
|
bl_label = "Simple Modal View3D Operator"
|
||||||
|
|
||||||
def modal(self, context, event):
|
def modal(self, context, event):
|
||||||
@@ -65,13 +65,18 @@ class ModalDrawOperator(bpy.types.Operator):
|
|||||||
self.report({'WARNING'}, "View3D not found, cannot run operator")
|
self.report({'WARNING'}, "View3D not found, cannot run operator")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
def menu_func(self, context):
|
||||||
|
self.layout.operator(ModalDrawOperator.bl_idname, text = "Modal Draw Operator")
|
||||||
|
|
||||||
|
# Register and add to the "view" menu (required to also use F3 search "Modal Draw Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(ModalDrawOperator)
|
bpy.utils.register_class(ModalDrawOperator)
|
||||||
|
bpy.types.VIEW3D_MT_view.append(menu_func)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(ModalDrawOperator)
|
bpy.utils.unregister_class(ModalDrawOperator)
|
||||||
|
bpy.types.VIEW3D_MT_view.remove(menu_func)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -31,13 +31,17 @@ class ModalTimerOperator(bpy.types.Operator):
|
|||||||
wm = context.window_manager
|
wm = context.window_manager
|
||||||
wm.event_timer_remove(self._timer)
|
wm.event_timer_remove(self._timer)
|
||||||
|
|
||||||
|
def menu_func(self, context):
|
||||||
|
self.layout.operator(ModalTimerOperator.bl_idname, text=ModalTimerOperator.bl_label)
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(ModalTimerOperator)
|
bpy.utils.register_class(ModalTimerOperator)
|
||||||
|
bpy.types.VIEW3D_MT_view.append(menu_func)
|
||||||
|
|
||||||
|
# Register and add to the "view" menu (required to also use F3 search "Modal Timer Operator" for quick access)
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(ModalTimerOperator)
|
bpy.utils.unregister_class(ModalTimerOperator)
|
||||||
|
bpy.types.VIEW3D_MT_view.remove(menu_func)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -57,13 +57,18 @@ class ViewOperator(bpy.types.Operator):
|
|||||||
self.report({'WARNING'}, "Active space must be a View3d")
|
self.report({'WARNING'}, "Active space must be a View3d")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
def menu_func(self, context):
|
||||||
|
self.layout.operator(ViewOperator.bl_idname, text = "Simple View Modal Operator")
|
||||||
|
|
||||||
|
# Register and add to the "view" menu (required to also use F3 search "Simple View Modal Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(ViewOperator)
|
bpy.utils.register_class(ViewOperator)
|
||||||
|
bpy.types.VIEW3D_MT_view.append(menu_func)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(ViewOperator)
|
bpy.utils.unregister_class(ViewOperator)
|
||||||
|
bpy.types.VIEW3D_MT_view.remove(menu_func)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -95,13 +95,18 @@ class ViewOperatorRayCast(bpy.types.Operator):
|
|||||||
self.report({'WARNING'}, "Active space must be a View3d")
|
self.report({'WARNING'}, "Active space must be a View3d")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
def menu_func(self, context):
|
||||||
|
self.layout.operator(ViewOperatorRayCast.bl_idname, text="Raycast View Modal Operator")
|
||||||
|
|
||||||
|
# Register and add to the "view" menu (required to also use F3 search "Raycast View Modal Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(ViewOperatorRayCast)
|
bpy.utils.register_class(ViewOperatorRayCast)
|
||||||
|
bpy.types.VIEW3D_MT_view.append(menu_func)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(ViewOperatorRayCast)
|
bpy.utils.unregister_class(ViewOperatorRayCast)
|
||||||
|
bpy.types.VIEW3D_MT_view.remove(menu_func)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -46,13 +46,18 @@ class NodeOperator(bpy.types.Operator):
|
|||||||
main(self, context)
|
main(self, context)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
def menu_func(self, context):
|
||||||
|
self.layout.operator(NodeOperator.bl_idname, text=NodeOperator.bl_label)
|
||||||
|
|
||||||
|
# Register and add to the "Node" menu (required to also use F3 search "Simple Node Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(NodeOperator)
|
bpy.utils.register_class(NodeOperator)
|
||||||
|
bpy.types.NODE_MT_node.append(menu_func)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(NodeOperator)
|
bpy.utils.unregister_class(NodeOperator)
|
||||||
|
bpy.types.NODE_MT_node.remove(menu_func)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -19,13 +19,18 @@ class SimpleOperator(bpy.types.Operator):
|
|||||||
main(context)
|
main(context)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
def menu_func(self, context):
|
||||||
|
self.layout.operator(SimpleOperator.bl_idname, text=SimpleOperator.bl_label)
|
||||||
|
|
||||||
|
# Register and add to the "object" menu (required to also use F3 search "Simple Object Operator" for quick access)
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(SimpleOperator)
|
bpy.utils.register_class(SimpleOperator)
|
||||||
|
bpy.types.VIEW3D_MT_object.append(menu_func)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(SimpleOperator)
|
bpy.utils.unregister_class(SimpleOperator)
|
||||||
|
bpy.types.VIEW3D_MT_object.remove(menu_func)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user