0
$\begingroup$

Hello i created a custom operator preset system.

i'd like to know how to have acces to the name of an active preset. i think an example from any preset in blender could help me in my research.

There's no info about this anywhere.

Here is my set upenter image description here

This is the code i was able to collect so far

#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")

i need to find the bpy.data.window_managers["WinMan"].preset_name = "New Preset" for my addon menu. i don't know how this is possible ?

$\endgroup$
  • $\begingroup$ You mean this bpy.context.workspace.name and [ws.name for ws in bpy.data.workspaces]? $\endgroup$ – lemon Sep 7 '19 at 6:27
  • $\begingroup$ @lemon sorry for being unclear. i was referencing drop down presets. $\endgroup$ – DB3D Sep 7 '19 at 11:09
  • $\begingroup$ @lemon i updated the question/descritption $\endgroup$ – DB3D Sep 7 '19 at 12:05
  • 1
    $\begingroup$ I'm not skilled at that. But why don't you store the preset identification/name/whatever as an operator property? (not sure there is some Blender mechanism that does it automatically, except maybe by preset path). $\endgroup$ – lemon Sep 7 '19 at 12:53
  • 1
    $\begingroup$ It’s the bl_label of the preset menu. $\endgroup$ – AFWS Oct 11 '19 at 21:11
0
$\begingroup$

Thanks to @AFWS

print(bpy.types.CYCLES_PT_integrator_presets.bl_label)

active preset is in fact the name of the bl_label

$\endgroup$
0
+50
$\begingroup$

Adding to the answer of DB3D:

Assuming that panel for the preset uses preset_operator = "script.execute_preset" the selected preset is indeed stored in bl_label. This can be seen in class ExecutePreset(Operator) in the presets.py where the label is changed to the most recent selection when the operator is executed.

    # change the menu title to the most recently chosen option
    preset_class = getattr(bpy.types, self.menu_idname)
    preset_class.bl_label = bpy.path.display_name(basename(filepath))

The code is licensed under GNU GENERAL PUBLIC LICENSE Version 3

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.