0
$\begingroup$

I have a multi file Addon where I want to set a default value for uv layers in the Addon preferences, while being able to choose a specific layout per file.

I set my preferences and make sure they get registered/unregistered:

class MY_AddonPreferences(AddonPreferences):
        
bl_idname = __package__
        
default_uvmethod_0: EnumProperty(
    items=[
        ('SWATCH', '', ''),
        ('LIGHTMAP', '','')
        ],
    default = 'SWATCH')

I make sure I can change the addon preferences in an addon preferences menu and define my Pointer properties and make sure they get registered/unregistered

class MY_SceneProperties(PropertyGroup):
            
addon_pref = bpy.context.preferences.addons['MyAddon'].preferences

action_uvmethod_0: EnumProperty( 
items=[
    ('SWATCH', '', ''),
    ('LIGHTMAP', '','')
    ],
    default = addon_pref.default_uvmethod_0)

I have no issues setting up the panels with these properties, the only issue is that somehow the 'addon_prefs' are not able to find my addon preferences even though I make sure they get registered first, It gives me this error:

enter image description here

If someone could point me in the right direction here I would be eternally gratefull

$\endgroup$
1
  • 1
    $\begingroup$ Hello ! There are several issues here. 1-You can't change the default value of an enum property once it's set. 2-You can't access bpy.context at the time of registration, it's not initialized yet. 3- At the time of registration you can't call MY_SceneProperties.addon_pref since you're calling it from within the class annotations definition. 4- Even if you could, you're calling addon_pref which doesn't look like the same as MY_SceneProperties.addon_pref. I think you want to explore get and set docs.blender.org/api/current/… $\endgroup$
    – Gorgious
    Dec 15, 2022 at 17:08

0

You must log in to answer this question.

Browse other questions tagged .