How to append two operators in the same menu

Hello. I’m writing a script to globally toggle object properties like wire, show-all-edges, shadeless material, and other things.

I have wrote this code. In the code I create two functions and two operators. I want to add both to the Object Mode Specials Menu, but the code adds only the second operator (the one wich toggle the show-all-edges property.

How can I make that both operators appears in the menu?

Thankyou!

import bpy
from bpy.props import IntProperty, FloatProperty, BoolProperty

global sel
sel = bpy.context.selected_objects


#funzione che controlla la proprietà show wire 
def wire_control():
    
    act_obj = bpy.context.active_object
    wire_value = not(act_obj.show_wire)
    for obj in sel:        
        if obj.type == 'MESH' or obj.type == 'CURVE':
            
            obj.show_wire = wire_value

#funzione che controlla la proprietà all-edges                  
def all_edges_control():
    
    act_obj = bpy.context.active_object
    all_edges_value = not(act_obj.data.show_all_edges)
    for obj in sel:        
        if obj.type == 'MESH' or obj.type == 'CURVE':
            
            obj.data.show_all_edges = all_edges_value


class OBJECT_OT_wire_control(bpy.types.Operator):
 
    bl_idname = "object.wire_control"
    bl_label = "Toggle the wire"
    bl_options = {'REGISTER'} 
    
    def execute(self, context):                      
        wire_control() 
        return {'FINISHED'}       
   
class OBJECT_OT_all_edges_control(bpy.types.Operator):
 
    bl_idname = "object.all_edges_control"
    bl_label = "Toggle all edges visibility"
    bl_options = {'REGISTER'} 
    
    def execute(self, context):                      
        all_edges_control() 
        return {'FINISHED'}       

def menu_func_wire(self, context):
    self.layout.operator("object.wire_control", text="Toggle Wire")
   
def menu_func_all_edges(self, context):
    self.layout.operator("object.all_edges_control", text="Toggle Show All Edges")
    
  
def register():
   bpy.utils.register_module(__name__)
   bpy.types.VIEW3D_MT_object_specials.append(menu_func_wire) 
 
def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.VIEW3D_MT_object_specials.remove(menu_func_wire)    

def register():
   bpy.utils.register_module(__name__)
   bpy.types.VIEW3D_MT_object_specials.append(menu_func_all_edges) 
 
def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.VIEW3D_MT_object_specials.remove(menu_func_all_edges)  
    
if __name__ == "__main__":
    register()   

I have another question: how could I add this two operators in a sub-menu of the Specials menu?

Thankyou!


import bpy
from bpy.props import IntProperty, FloatProperty, BoolProperty


#funzione che controlla la proprietà show wire 
def wire_control(context):
    sel = context.selected_objects
    act_obj = context.active_object
    wire_value = not(act_obj.show_wire)
    for obj in sel:        
        if obj.type == 'MESH' or obj.type == 'CURVE':
            
            obj.show_wire = wire_value

#funzione che controlla la proprietà all-edges                  
def all_edges_control(context):
    
    act_obj = context.active_object
    sel = context.selected_objects
    all_edges_value = not(act_obj.data.show_all_edges)
    for obj in sel:        
        if obj.type == 'MESH' or obj.type == 'CURVE':
            
            obj.data.show_all_edges = all_edges_value


class OBJECT_OT_wire_control(bpy.types.Operator):
 
    bl_idname = "object.wire_control"
    bl_label = "Toggle the wire"
    bl_options = {'REGISTER'} 
    
    def execute(self, context):                      
        wire_control(context) 
        return {'FINISHED'}       
   
class OBJECT_OT_all_edges_control(bpy.types.Operator):
 
    bl_idname = "object.all_edges_control"
    bl_label = "Toggle all edges visibility"
    bl_options = {'REGISTER'} 
    
    def execute(self, context):                      
        all_edges_control(context) 
        return {'FINISHED'}       

class SimpleCustomMenu(bpy.types.Menu):
    bl_label = "Simple Custom Menu"
    bl_idname = "OBJECT_MT_simple_custom_menu"

    def draw(self, context):
        layout = self.layout

        layout.operator("wm.open_mainfile")
        layout.operator("wm.save_as_mainfile")


def menu_funcs(self, context):
    self.layout.operator("object.wire_control", text="Toggle Wire")
    self.layout.operator("object.all_edges_control", text="Toggle Show All Edges")
    self.layout.menu("OBJECT_MT_simple_custom_menu")

    
  
def register():
   bpy.utils.register_module(__name__)
   bpy.types.VIEW3D_MT_object_specials.append(menu_funcs) 
 
def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.VIEW3D_MT_object_specials.remove(menu_funcs)    


    
if __name__ == "__main__":
    register()

PS noticed the sub menu part… added the simple menu example change it to suit your needs.

Thankyou! That’s really what I needed!