bpy.types.VIEW3D_MT_view.remove
takes a reference to the function.
But each time the code runs, a new version of the draw function is created.
Removing the old function requires looping over the draw list and identifying the function by some other trait. One example could be the function’s __name__
attribute, assuming the function isn’t renamed.
import bpy
def VIEW3D_menu_item(self, context):
self.layout.label(text='Hello')
def register():
bpy.types.VIEW3D_MT_view.append(VIEW3D_menu_item)
def unregister():
for f in bpy.types.VIEW3D_MT_view._dyn_ui_initialize():
if f.__name__ == VIEW3D_menu_item.__name__:
bpy.types.VIEW3D_MT_view.remove(f)
return
unregister()
register()