is it possible to check a script status running by Text Editor 'Run Script' or running as Addon? I wrote a Script to manipulate Vertices, and the script adds an menu entry. For testing this could be very helpful to avoid tons of menu entrys.

def register():
# the hypothetical request:
if script runasAddon: # (or something like that)
  • 1
    $\begingroup$ Hi, added an answer, wondering if it's an idea to change question a bit to make it more "Making sure there is only one draw method ap(pre)pended to a Menu / Panel class." as I assume you still want one menu entry either way. $\endgroup$
    – batFINGER
    Commented Sep 10, 2016 at 10:41
  • $\begingroup$ possible duplicate blender.stackexchange.com/questions/3394/… $\endgroup$
    – zeffii
    Commented Sep 10, 2016 at 14:06
  • $\begingroup$ When working with addons I prefer to use an external text editor and disable/enable the addon so that items get removed. When running non-addon scripts I use this addon to run the script within the python console so that I can see any output and access the variables after the script has run. $\endgroup$
    – sambler
    Commented Sep 10, 2016 at 15:37

2 Answers 2


It is possible to know that your script is being run within blender, you most likely have seen the line if __name__ == "__main__": in many blender scripts. This resolves to true when the script is run as a script, when false the script is being started as an addon.

Note that the else clause will be run when you first enable the addon or if you modify the addon file and disable/enable it again, it will not be run if you disable then enable an unmodified addon file.

if __name__ == "__main__":
    print('run as script')
    print('starting addon')
  • $\begingroup$ thank you, That's exactly what I need def register(): bpy.utils.register_module(name) if name != "main": bpy.types.VIEW3D_MT_edit_mesh_vertices.append(menu_func) works fine. $\endgroup$
    – UncleTeo
    Commented Sep 11, 2016 at 15:46

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 remove_draw_pend(...) from 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 remove_draw_pend(panelclass, "SD_")

Test script, running the script below multiple times will result in "FUNKY" only appearing once in menu.

import bpy

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()
                  if f.__name__.startswith(prefix)]

    for f in draw_funcs:

def funky(self, context):

def register():
    if True: # __package__ is None: # 
        remove_draw_pend(bpy.types.VIEW3D_MT_edit_mesh_vertices, "funky")    

if __name__ == "__main__":

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .