Cleanliness whilst testing

Hi,

I’m using the following code (from).

Whilst developing / testing I obviously make changes. When I rerun the script it adds duplicate menu items, how do I stop this? I’ve tried using print() in the menu_func() but nothing is printed!?

I’ve also added the unregister() call in main() which stops the modules from being duplicated, this may not be right method either?

Thanks



import bpy

from bpy.props import *

class MESH_OT_primitive_twisted_cylinder_add(bpy.types.Operator):
    '''Add something'''
    bl_idname = "mesh.primitive_twisted_cylinder_add"
    bl_label = "Add twisted cylinder 111"
    bl_options = {'REGISTER', 'UNDO'}
    
    def execute(self, context):
        print("hello from execute")
        return {'FINISHED'}

class MESH_OT_primitive_twisted_cylinder_add2(bpy.types.Operator):
    '''Add something'''
    bl_idname = "mesh.primitive_twisted_cylinder_add2"
    bl_label = "Add twisted cylinder 222"
    bl_options = {'REGISTER', 'UNDO'}
    
    def execute(self, context):
        print("hello from execute 2")
        return {'FINISHED'}

#
#    Registration
#    Makes it possible to access the script from the Add > Mesh menu
#
 
def menu_func(self, context):
    print("registering")
    print(dir(self.layout))
    self.layout.operator("mesh.primitive_twisted_cylinder_add", text="Add Tester 1", icon='MESH_TORUS')
    self.layout.operator("mesh.primitive_twisted_cylinder_add2", text="Add Tester 2", icon='MESH_TORUS')
 
def register():
   bpy.utils.register_module(__name__)
   bpy.types.INFO_MT_mesh_add.prepend(menu_func)
 
def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_mesh_add.remove(menu_func)
 
if __name__ == "__main__":
    unregister()
    register()