Custom Properties - User Preferences

I’m trying to add a custom property to UserPreferences, something like this:


bpy.types.UserPreferences.Verbose = bpy.props.BoolProperty(
name=“Verbose”,
description=“Output debug info.”,
default=False)

…panel code…

def draw(self, context):
    layout = self.layout

    prefs = context.user_preferences

    row = layout.row()
    row.prop(prefs, "Verbose")

The panel code complains that ‘property not found’. Properties attached to Object, Scene etc. work fine.

Is there someplace to store custom preference type properties in the blend file? Google seems oddly quiet on the matter.

Thanks.

Strange,

If you look in the console



>>> C.user_preferences.Verbose
(<built-in function BoolProperty>, {'default': False, 'description': 'Output debug info.', 'name': 'Verbose'})

You get the Boolproperty function rather than False. Maybe WindowManager if you don’t want to use Scene.

UserPreference seems not to work because it is not an ID type object. ‘WindowManager’ works, as it is an ID object. However, it appears that properties of WindowManager do not persist in the .blend file.

If I add these properties to ‘Scene’ everything works fine. Problem is I now need to support multiple scenes, and it does not make sense to attach what is supposed to be a global property to a specific scene.

There has to be someplace in the .blend file where such properties are stored. Any ideas on the official way to do this?

Thanks.

Based on your first post looking at debug and verbose you could use something like this There is one enum prop connected to the scene that is used to set bpy.app.debug and bpy.app.debug_value. Only scene[0] is displayed in the panel.

Excuse the hodgepodge code made up of recent examples.


import bpy


def debuglevel(self,context):
    debug_lev = int(self.list)
    print("debuglevel %d"%self.list)
    if debug_lev < 0:
        bpy.app.debug = False
    else:
        bpy.app.debug = True
    bpy.app.debug_value = debug_lev
    

def objectsnames():
    
    items = "(('-1','OFF',''),('0','level0',''),('1','level1',''),('2','level2',''))"
    myitems = eval(items)
    
    return myitems
  
               
class OBJECT_PT_hello(bpy.types.Panel):
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"
    bl_label = "Debug Level"

    myitems = objectsnames()
    bpy.types.Scene.list = bpy.props.EnumProperty(name="Objects",items=myitems,update=debuglevel,default=str(bpy.app.debug_value))
    
    def draw(self, context):
        layout = self.layout
        scene = bpy.data.scenes[0]
        row = layout.row()
        row.prop(scene, "list",expand=True)

def register():
    bpy.utils.register_class(OBJECT_PT_hello)
def unregister():
    bpy.utils.unregister_class(OBJECT_PT_hello)

if __name__ == "__main__":
    register()