How can I check if a draw function exists in a Menu before registering? When I write prototypes in the Text Editor, I get multiple draw functions added in Blender’s UI.
Inspired by this post, I am iterating through bpy.types.VIEW3D_MT_object._dyn_ui_initialize() and comparing it to my draw function’s name. If it doesn’t exist, I’m appending it to the Menu:
def object_menu(self, context):
self.layout.label(text="Test")
def register():
omenu = next(iter([f for f in bpy.types.VIEW3D_MT_object._dyn_ui_initialize() if f.__name__ == object_menu.__name__]),None)
if not omenu:
bpy.types.VIEW3D_MT_object.append(object_menu)