Setting a panel property (slider) from user settings slider?

If I put a slider on a panel in the ‘user settings’ for an addon, how do I make that same slider appear on a panel in, for example, the 3D view? Is this possible?

I tried to do it with a different slider, but I’m having panel draw context problems when I try to retrieve the value of the ‘user settings’ slider and set another slider on a panel in the 3D view to the same value.

Thanks

It’s possible, but i’m pretty sure you need to hit “Save Settings” in the user prefs to store the property.


class ExampleAddonPreferences(AddonPreferences):
    bl_idname = __name__

    object_active = FloatVectorProperty(
            name="Object Active",
            description="Active object's color",
            subtype='COLOR_GAMMA',
            min=0.0, max=1.0)

    def draw(self, context):
        layout = self.layout
        layout.label(text="This is a preferences view for our addon")
        layout.prop(self, "the_preference_prope")

# ...

draw_func(self, context):
    self.layout.prop(context.user_preferences.addons['your_addon_name'].preferences, "the_preference_prop")

bpy.types.VIEW3D_PT_tools_objectmode.prepend(draw_func) # add to T-panel object tools

Thanks CoDEmanX.

I thought it was something like that. I couldn’t quite get it though.
This was for my ‘Script Runner’ addon. It now gives you the option of settings, but not saving, the number of displayed scripts from the panel.

Also, I took your advice and replaced that loud, glaring, red-icon.
Funny, I wanted the other one, but my tired eyes couldn’t find it in the sea of icons displayed in the ‘All icons’ addon.
I looked again and it was there of course.

Download version 1.3 here: http://goodspiritgraphics.com/software/tutorials/blender-tutorials/script-runner-addon/

Here is the code that works:

class ScriptRunnerAddonPreferences(AddonPreferences):
    bl_idname = __name__ 
    
    num_scripts = IntProperty(name="Number of Scripts", 
    description = "Set to the number of scripts to display in the panel", min = 1, max = 10, default = 2)

    def draw(self, context):
        user_settings = bpy.context.user_preferences.addons[__name__].preferences
  
        layout = self.layout
             
        row.label("Number of Script Slots to Display:")
        row = layout.row()
        row.prop(self, "num_scripts", text="Scripts", slider = False)


Then add this function:

def draw_scripts_slider(self, context):
    self.layout.prop(context.user_preferences.addons['script_runner'].preferences, "num_scripts",  text="Scripts")

Lastly, display it on any panel in the draw function like this:

    def draw(self, context):
        
            #Copy the slider from the addon user preferences.
            draw_scripts_slider(self, context)