User Preference and custom properties

Hi, I’m working on a complex script, so I’ve separate it in different file:
init.py (user interface and custom properties)
setting.py (property settings on user preferences)
operators.py

In the setting.py I create the class for the panel in Addons User Preference.
So it store a property like this:

col = BoolProperty(name="Colors",description="Randomize",default=True)

The property is now accesseible from:

user_preferences = context.user_preferences
addon_prefs = user_preferences.addons['color_randomize'].preferences

and

addon_pref.col

So when I create the custom property like this in the init.py:

bpy.types.Scene.col = BoolProperty(name="Randomize Colors",
        description="Randomize",
        default=addon_pref.col)

I receive an error, because blender don’t find the addon_pref.col

I’ve the right code on the top of init.py to import the module and the classes:

if "bpy" in locals():
    import imp
    imp.reload(operators)
    imp.reload(settings)
else:
    from . import operators  
    from . import settings  

Sorry for my bad English, I hope you have understand the problem :smiley:

This looks a bit like something I remember reading recently but I can’t recall where (sorry)
Anyway it said basically for the properties to register properly you needed to use
bl_idname = name
in your prefferences class
this would then be mapped to the file name and it would work.
If you have split off the settings into a different file this could be where it’s getting lost.
Sorry for my bad Italian
Also sorry for my limited knowledge I just thought this might help.

The preferences properties work, the bl_idname is “color_randomize”.
The problem is that the preferences can’t be saved in the working.blend file, but only in the user preferences panel, how default data.
If you reload the working.blend file your properties are keep from the user preference.

So, I have create a second properties type, store in the bpy.types.Scene, this prop are saved in the active scene.
I want that the prop in scene, has as default value, the prop in the user preferences.

Who use the script, set at first the props in the preference, as default for every first load of the script.
And the props in the scene are store for each working.blend file that the user want to create.

addon_prefs = user_preferences.addons[‘color_randomize’].preferences

Note that addon_prefs is probably just a local variable, if you try to access it in a panel class, it won’t exist in that class’ scope.

It is the inverse…
addon_prefs.col show me the value (True) in the panel class, but above, where I create the Scene.col prop it don’t find the preferences value.

reference it explicitly and it should work, as (bpy.)context is global

Maybe try bl_idname = package instead of bl_idname = name if you have split into several modules.

the init.py:
http://www.pasteall.org/blend/31637
The settings.py:
http://www.pasteall.org/blend/31638

I want that the default of “color” in the RandomizeColorSettings Class is the “color” prop in the ColorPreferences class

please don’t upload py files to pasteall, just paste the code instead.

You can make this a set {‘EDIT_MESH’, …}

EDIT = ["EDIT_MESH", "EDIT_CURVE", "EDIT_SURFACE", "EDIT_METABALL", "EDIT_TEXT", "EDIT_ARMATURE"]

This isn’t a valid idname:

     bl_idname = "_PT_randomize_cover"

It should be “VIEW3D_PT_randomize_cover”

Get rid of try/except here:

    @classmethod
    def poll(self, context):
        try:
            return (context.mode not in EDIT)
        except (AttributeError, KeyError, TypeError):
            return False

There’s always a context with a mode attribute

This needs to be package, as dustractor pointed out:

    bl_idname = 'pref'

An empty string IS the default

    palette_img = StringProperty(name="Palette Image", default='')

You can’t use a property’s value as default for another, it is not supported (context is restricted at registration time). You might be able to set the value on a user action, such as a button click however.

Thanks for the corrections :).
I’ve to find another way to save this prop…