Rather than adding code as you suggest,
If you are testing addon code from the script editor, you can press F8 which is the equivalent of
which will take out all the menu entries added by scripts run from the text editor.
Another method is to remove draw methods from a panel (or menu) class. Here is a quick example using
sound_drivers.utils In sound_drivers I spit a lot of draw methods into PROPERTY panels that have an "SD_" prefix, I remove these in one fell swoop with
Test script, running the script below multiple times will result in "FUNKY" only appearing once in menu.
def remove_draw_pend(paneltype, prefix):
remove all functions with name beginning
with prefix (pre/ap)pended to paneltype
draw_funcs = [f for f in paneltype._dyn_ui_initialize()
for f in draw_funcs:
def funky(self, context):
if True: # __package__ is None: #
if __name__ == "__main__":