2
$\begingroup$

I am very new to Blender. Exploring it i have found a scripting template called "Addon Add Object". When i open and run it i see as much menu entries in the Add>Mesh menu as i ran the script.

Steps to reproduce my problem:

  1. open the Scripting view
  2. Click on Templates>Python>Addon Add Object
  3. Click on button "Run Script"
  4. in 3d View open the Add>Mesh menu and see a new entry named "Add Object"
  5. repeat step 3.
  6. in 3d View open the Add>Mesh menu and see another entry named "Add Object" AND the previous one is not removed.

As far as I understood the script, in line 88 the menu entry should be removed, but it is not.

Is that an error?

Did i miss something?

How can i remove the obsolete menu entry then?

I tried to find an answer myself, but the problem is so specific, that i did not know what to search for in Google.

$\endgroup$
0

1 Answer 1

2
$\begingroup$

If you run from the main thread, via the text editor the "addon" is only registered (the if __name__ == "__main__" bit). Doing this is for testing purposes, and is not meant to be a way to run addons.

To remove, go to python console and type in the following:

bpy.ops.script.reload() 

Or via the menu Blender > System > Reload Scripts

the shortcut for which prior to 2.8 is F8

When an addon is enabled, it is imported as a module and the register method is called. When addon is disabled the module's unregister method is called.

Addons are designed to be enabled and registered via the addons in user prefs, or by putting in scripts folder, or by making it a registered script in the text editor.

Related: unregistering a class

Using the py console.

For single file scripts like above can also emulate them being a module (as if they were imported like an addon) from the python console.

For example if the text block has name "add_object.py" then can "import" it as a module via

>>> add_object = D.texts['add_object.py'].as_module()

call its register method

>>> add_object.register()

and its unregister method, which will remove the draw method from the menu.

>>> add_object.unregister()
>>> 
$\endgroup$

You must log in to answer this question.

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