How to set up a preset system

code look like something like that
`bpy.data.window_managers[“WinMan”].preset_name = “New Preset” but for the addon.

@AFWS any ideas? :pray:

Should be bpy.types.WindowManager.preset_name.

It need’s the data path to the menu first in able to work no ? for example somthing like that ?
i just don’t uderstand how to find this path
bpy.context.scene.Scatter_MT_C_Slots_PresetMenu.preset_name

This is all the related code i was able to get so fat.

#this is the correct code mut within blender ! no with my addon
bpy.data.window_managers["WinMan"].preset_name = "New Preset"
#call preset menu of nlender ! not my addon
bpy.ops.wm.call_panel(name="CYCLES_PT_sampling_presets")

#add a new preset
bpy.ops.scatter.custom_slot_preset_add_operator(name="Wow", remove_name=False, remove_active=False)
#execute a preset from my addon
bpy.ops.script.execute_preset(filepath="filepathofthepreset", menu_idname="Scatter_MT_C_Slots_PresetMenu")
#call preset menu 
bpy.ops.wm.call_menu(name="Scatter_MT_C_Slots_PresetMenu")

print(bpy.data.window_managers[“Scatter_MT_C_Slots_PresetMenu”].preset_name)

didn’t work either

anyone have an idea how to have the name / change the active preset

Might not be possible.

1 Like

Nooo :frowning:
Thanks for your link.

But at least with script.execute_preset we can manually execute the preset right ?

Maybe this helps some. Looks like it changes the bl_label.

https://developer.blender.org/diffusion/B/browse/master/release/scripts/startup/bl_operators/presets.py$242

OK, this work for “Light Paths” in 2.79.

print(bpy.types.CYCLES_MT_integrator_presets.bl_label)

See what this gives you.

print(bpy.types.Scatter_MT_C_Slots_PresetMenu.bl_label)

No waaaaaay :smiley: it worked

1 Like

Just created operator an operator to skip to next or previous preset. the drop menu is kind of tiring.

I just wanted to share this.

class SCATTER_OT_skip_prev(bpy.types.Operator):
    bl_idname = "scatter.skip_prev"
    bl_label = ""
    bl_description = ""


    left0_right1 : bpy.props.IntProperty()
    def execute(self, context):
        left0_right1 = self.left0_right1
        
        directory = os.path.join(bpy.utils.user_resource('SCRIPTS'), "presets", "scatter_presets_custom\\")

        from os import listdir
        from os.path import isfile, join

        onlyfiles = [f for f in listdir(directory) if isfile(join(directory, f))]

        list_choice=[]
        for f in onlyfiles:
            if f[-3:] == ".py":
                list_choice.append(f[:-3].replace("_", " ").title()) #Addon pref preset by defautl necessary !!!!

        i = list_choice.index(bpy.types.Scatter_MT_C_Slots_PresetMenu.bl_label)

        #PREV
        if left0_right1 ==0:
            if i == 0: i=len(list_choice) #loop
            bpy.types.Scatter_MT_C_Slots_PresetMenu.bl_label = list_choice[i-1]

        #NEXT
        elif left0_right1 ==1:
            if i == len(list_choice)-1: i=-1 #loop
            bpy.types.Scatter_MT_C_Slots_PresetMenu.bl_label = list_choice[i+1]

        return {'FINISHED'}

*edit: forgot to execute the preset

class SCATTER_OT_skip_prev(bpy.types.Operator):
    bl_idname = "scatter.skip_prev"
    bl_label = ""
    bl_description = ""


    left0_right1 : bpy.props.IntProperty()
    def execute(self, context):
        left0_right1 = self.left0_right1

        directory = os.path.join(bpy.utils.user_resource('SCRIPTS'), "presets", "scatter_presets_custom\\")
        from os import listdir
        from os.path import isfile, join
        onlyfiles = [f for f in listdir(directory) if isfile(join(directory, f))]

        list_choice=[]
        list_raw=[]
        for f in onlyfiles:
            if f[-3:] == ".py":
                list_choice.append(f[:-3].replace("_", " ").title()) #Addon pref preset by defautl necessary !!!!
                list_raw.append(f)

        i = list_choice.index(bpy.types.Scatter_MT_C_Slots_PresetMenu.bl_label)

        #PREV
        if left0_right1 ==0:
            if i == 0: i=len(list_choice)#(already +1 as len don't start from 0) #loop
            bpy.types.Scatter_MT_C_Slots_PresetMenu.bl_label = list_choice[i-1]
            bpy.ops.script.python_file_run(filepath=directory+list_raw[i-1])

        #NEXT
        elif left0_right1 ==1:
            if i == len(list_choice)-1: i=-1 #loop
            bpy.types.Scatter_MT_C_Slots_PresetMenu.bl_label = list_choice[i+1]
            bpy.ops.script.python_file_run(filepath=directory+list_raw[i+1])

        #bpy.ops.script.execute_preset(filepath=directory+, menu_idname="")

        return {'FINISHED'}

here we go

1 Like