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()