TransWikia.com

Class already registered as subclass (module structure for addon)

Blender Asked by BlendingJake on February 5, 2021

I am working on creating an addon and I have a main __init__.py file and then I have a another file we will call utils.py. __init__ registers all the classes in utils by import utils and then bpy.utils.register_class(utils.CLASS), it has several classes and that file registers them all.

If you run the file once it works fine, but if you run it again it gives the error that the class is already registered as a subclass.

utils contains a bpy.types.Panel and bpy.types.Operator class. It is almost like the bpy.utils.unregister_class(utils.CLASS) isn’t working. File

2 Answers

This happens when you load the same add on multiple times. Try removing the add on. close the blender. Relaunch the blender and now try adding the add on. Worked for me.

Answered by Rishabh Mathur on February 5, 2021

You can replace all calls to bpy.utils.register_class(...) by a single call to

bpy.utils.register_module(__name__)

and all calls to bpy.utils.unregister_class(...) by a single

bpy.utils.unregister_module(__name__)

You won't have to (un-)register single classes ever again and your error should no longer occur. Do it in __init__.py only and import all module files from here (from . import ...).

Note that the order of class definitions may matter, e.g. if you use a custom property group class in an operator (the code of the property group class needs to be above the class definition of the operator).

Example addon to show the file structure and imports: blender-addon.zip

Answered by CodeManX on February 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP