0
$\begingroup$

I have multiple scripts that i would like to turn into an addon. I already have everything it needs, but i when i click the button to enable the addon in the user preferences it says:

  bpy.utils.register_class(SCAPANEL)
  ValueError: register_class(...): already registered as a subclass

I imported every other file I need via from .example import example and put these files in one folder. I even looked up other blender addons, but that didn't help either.

Edit:

def register():
   bpy.utils.register_class(SCAPANEL)
   bpy.utils.register_class(SCA)
   bpy.utils.register_class(Skin)
   bpy.utils.register_class(removeDoubles)
   bpy.utils.register_class(thin)
   bpy.types.Scene.Tree = bpy.props.StringProperty()
   bpy.utils.register_class(particlesystem)
   bpy.types.Scene.Growth_limitation = bpy.props.BoolProperty()
   bpy.types.Scene.limiter = bpy.props.StringProperty()


def unregister():
   bpy.utils.unregister_class(SCAPANEL)
   bpy.utils.unregister_class(SCA)
   bpy.utils.unregister_class(Skin)
   bpy.utils.unregister_class(removeDoubles)
   bpy.utils.unregister_class(thin)
   bpy.utils.unregister_class(particlesystem)
   del bpy.types.Object.Tree
   del bpy.types.Object.Growth_limitation
   del bpy.types.Object.limiter


register()

These are only the register and unregister functions. I noticed that my panels sitll shows up, even though the box is not ticked. When I try to execute my script it says, that it cannot perform a relative import.

$\endgroup$
  • 1
    $\begingroup$ From the information provided it is only possible to be certain that there is a problem with the code. If the answer does not satisfy you, you will need to share the code obviously. $\endgroup$ – Martin Z Sep 27 '18 at 13:48
  • 1
    $\begingroup$ The error is pretty self explanatory you are trying to register an already registered blender class. Often this is due to not unregistering the class properly, noticeable particularly if you are testing enabling and disabling your addon. $\endgroup$ – batFINGER Sep 27 '18 at 13:55
2
$\begingroup$

Enabling an addon calls register

The issue in new code posted is the lack of

if __name__ == "__main__":
     register() 

(pretty much ubiquitous in all blender addons and UI code etc etc, or for python command line scripts) Without this conditional register() will be run on import (Worth noting on import __name__ is the module name, ie not matching "__main__").

When an addon is enabled it is imported and calls its module.register() Henceforth your code is registering a second time and throws the error on the first class registered in register method.

The conditional code is there so scripts can be tested in the text editor.

Note: another thing to look for: for registered classes the bl_idname property is how they are known to blender.

$\endgroup$
  • $\begingroup$ Yes that worked. But now it says "cannot perform relative import" when i try to import a class form another script. $\endgroup$ – Nebeig Sep 28 '18 at 7:41
  • $\begingroup$ I could solve the problem. I named the main file init.py and put every python file i needed in a .zip folder. $\endgroup$ – Nebeig Sep 29 '18 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.