can we modify / add to user preferences

can you modify / add to the ui in the user preferences

i want to add in the user preferences ui a new button that lets you look for a working folder

And here’s how to add your own file pref.

import bpy

class USERPREF_PT_myfile(bpy.types.Panel):
    bl_space_type = 'USER_PREFERENCES'
    bl_label = "My Files"
    bl_region_type = 'WINDOW'
    bl_options = {'HIDE_HEADER'}

    @classmethod
    def poll(cls, context):
        userpref = context.user_preferences
        return (userpref.active_section == 'FILES')

    def draw(self, context):
        layout = self.layout
        layout.prop(context.window_manager, 'my_path')

def register():
    bpy.utils.register_class(USERPREF_PT_myfile)
    #UserPreferences type is not based on ID, so store elsewhere...
    bpy.types.WindowManager.my_path = bpy.props.StringProperty(
        name='My Path',
        subtype='DIR_PATH')

def unregister():
    bpy.utils.unregister_class(USERPREF_PT_myfile)

if __name__ == "__main__":
    register()

You can change the poll to display on panel in other preference screens. Have a look at scripts/ui/space_userprefs.py script for the appropriate settings. You could improve the layout to match too…

dude thats just what im looking for thanks

i have another question about the user preferences, i now have the select work folder i needed but how when i tried saving as default it didnt keep my folder… can someone tell me the code or where to find it

Sorry about that - I didn’t test saving. I’ve had another look and can’t find an obvious place to attach the property. Basically it needs to go on something that is saved in the default blend - I guess window_manager must be generated on startup rather than saved which would explain why it doesn’t work.

We need where ever we attach the property to always be available. And that’s where the problem lays. The following will work until someone renames or deletes the “Default” screen…

import bpy

class USERPREF_PT_myfile(bpy.types.Panel):
    bl_space_type = 'USER_PREFERENCES'
    bl_label = "My Files"
    bl_region_type = 'WINDOW'
    bl_options = {'HIDE_HEADER'}

    @classmethod
    def poll(cls, context):
        userpref = context.user_preferences
        return (userpref.active_section == 'FILES')

    def draw(self, context):
        layout = self.layout
        layout.prop(context.blend_data.screens['Default'], 'my_path')

def register():
    bpy.utils.register_class(USERPREF_PT_myfile)
    #UserPreferences type is not based on ID, so store elsewhere...
    bpy.types.Screen.my_path = bpy.props.StringProperty(
        name='My Path',
        subtype='DIR_PATH')

def unregister():
    bpy.utils.unregister_class(USERPREF_PT_myfile)

if __name__ == "__main__":
    register()

I guess long term solution would be to request an ID based preferences section for scripts to use. Unless I’m overlooking something and this can be done another way of course :wink: