Changing the Addon category in the Blender UI

This template shows how to change the category of an Addon in the Addon preferences. Does it have anything I should avoid?


bl_info = {
    "name": "Example Addon Preferences Change Category",
    "author": "Your Name Here",
    "version": (1, 0),
    "blender": (2, 70, 0),
    "location": "View3D > TOOLS > Example > Addon Preferences Example",
    "description": "Example Addon",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "UI"}


import bpy
from bpy.types import Panel, AddonPreferences
from bpy.props import StringProperty


class VIEW3D_PT_addon_prefs_example(Panel):
    """Display example preferences"""
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Example"
    bl_label = "Addon Preferences Example"


    def draw(self, context):
        addon_prefs = context.user_preferences.addons[__name__].preferences
        layout = self.layout
        layout.label(text="Change the category")
        layout.prop(addon_prefs, "category", text = "")


def update_panel(self, context):
    try:
        bpy.utils.unregister_class(VIEW3D_PT_addon_prefs_example)
    except:
        pass
    VIEW3D_PT_addon_prefs_example.bl_category = context.user_preferences.addons[__name__].preferences.category
    bpy.utils.register_class(VIEW3D_PT_addon_prefs_example)


class ExampleAddonPreferences(AddonPreferences):
    # this must match the addon name, use '__package__'
    # when defining this in a submodule of a python package.
    bl_idname = __name__


    category = bpy.props.StringProperty(
            name="Category",
            description="Choose a name for the category of the panel",
            default="Example",
            update=update_panel,
            )


    def draw(self, context):
        layout = self.layout
        layout.prop(self, "category")


# Registration
def register():
    bpy.utils.register_class(ExampleAddonPreferences)
    #bpy.utils.register_class(VIEW3D_PT_addon_prefs_example)
    update_panel(None, bpy.context)


def unregister():
    bpy.utils.unregister_class(VIEW3D_PT_addon_prefs_example)
    bpy.utils.unregister_class(ExampleAddonPreferences)

Wow… I need this feature to change the category as a separate addon. To help me organize a bunch of addons I have and put them where I wan them.

But mano-wii, what is the question, please? I don’t understand : “Does it have anything I should avoid?”

If all addons were produced this way greatly facilitate the organization of files. Change with each new version of an addon is a tiring and unproductive task. Congratulations to mano-wii again by the idea and initiative to make it easier for those who do not understand scripts.

Thank you guys :slight_smile:

Actually I wanted to say that I am aware of suggestions. So far I have not seen anything like this script.
English is not my native language, so sometimes I cannot be clear. :\

mano-wii seria possivel confeccionar um addon onde onde eu possa indicar o nome do addon que se deseja modificar a categoria e a seguir informar qual categoria a ser colocado? Desta forma poderia utilizar para todos os addons facilmente.

mano-wii would be possible to fabricate an addon where where I can indicate the addon name that you want to change the category and then inform what category to be placed? This way could be used for all addons easily.

You are doing a great job! Big Thx!

Hy @mano-wii!
I want to use your category change for a nested panel,
but i got no registration for it.
I don´t know how to fix it. Can you help?..

https://drive.google.com/file/d/0B5QQIWH-54S1YVBjQmhrSjMtSTQ/view?usp=sharing

Hy mano-wii!
i have replace the package template with the fixed one:
https://drive.google.com/file/d/0B5QQIWH-54S1QlA5eU9nTDVuTW8/view?usp=sharing
Thx for your help!

What happens if you run the update panel function in a loop for like 1 mio times? Does it leak memory? Ideasman once mentioned that class re-registering might do that.

I decided to do a test, I do not know if I got it right but I updated the panel 1000000 times.
All it took was run this code, once the name given to the module was “change_category”.
It took a little bit but did not leak memory.


import bpy


for a in range(1000000):
    bpy.context.user_preferences.addons['change_category'].preferences.category = str(a)
    bpy.context.scene.update()

@mkbreuer, the “update_panel()” has to look like this:


def update_panel(self, context):
    try:
        bpy.utils.unregister_class(VIEW3D_PT_addon_prefs_example)
    except:
        pass
    VIEW3D_PT_addon_prefs_example.bl_category = context.user_preferences.addons[__package__].preferences.category
    bpy.utils.register_class(VIEW3D_PT_addon_prefs_example)

And not the way it is:


def update_panel(self, context):
    try:
        bpy.utils.unregister_class(VIEW3D_PT_addon_prefs_example)
    except:
        pass
        VIEW3D_PT_addon_prefs_example.bl_category = context.user_preferences.addons[__package__].preferences.category
    bpy.utils.register_class(VIEW3D_PT_addon_prefs_example)

Be careful there.

A bit late, but honestly: Thank you!