1
$\begingroup$

I have a "Redo Panel" with some custom properties and an operator at the end, from which I want to reset all custom properties at their default values. How can I do that?

Here is an example of my code:

class FU3DM_OT_ModelPrefs(bpy.types.Operator):
    bl_idname = "fu3dm.model_prefs"
    bl_label = "Model"
    bl_description = "Blah blah blah"
    bl_options = {'REGISTER','UNDO'}

    gender : bpy.props.EnumProperty(name="Gender", description="Choose model's gender", items= [('OP1', "Male", ""), ('OP2', "Female", "")], default='OP1')
    head_male : bpy.props.EnumProperty(name="Head", description="Choose model's head", items= [('OP1', "Generic Male", ""), ('OP2', "Male", "")], default='OP2')
    head_female : bpy.props.EnumProperty(name="Head", description="Choose model's head", items= [('OP1', "Generic Female", ""), ('OP2', "Female", "")], default='OP2')
    eyes_color : bpy.props.IntProperty(name="Eyes Color", description="Choose model's eyes color", min=1, max=10, default=1)
    skin_color : bpy.props.IntProperty(name="Skin Color", description="Choose model's skin color", min=1, max=10, default=1)
    models_show : bpy.props.BoolProperty(name="Show Model", description="Show or hide models", default=1)

    class FU3DM_OT_ResetAll(bpy.types.Operator):
        bl_idname = "fu3dm.reset_all"
        bl_label = "Reset"
        bl_description = "Blah blah blah"
        bl_options = {'REGISTER', 'UNDO'}

        def execute(self, context):
            # ???
            return {"FINISHED"}

    def draw(self, context):
        layout = self.layout
        # ...
        row = layout.row()
        row.operator('fu3dm.reset_all')
        # ...

    def execute(self, context):
        # ...
        return {"FINISHED"}
$\endgroup$
4
  • 1
    $\begingroup$ If you right click on property will see it is an option to reset single or all to default. If you wish the operator to always start with the default values you have set see blender.stackexchange.com/questions/94035/… Btw noticed the nested operator classes in q code, is that working for you? $\endgroup$
    – batFINGER
    Commented Oct 19, 2020 at 9:42
  • $\begingroup$ "If you right click on property will see it is an option to reset single or all to default." Yes I have already seen that. Are you talking about this bpy.ops.ui.reset_default_button(all=True) and this bpy.ops.ui.unset_property_button()? If yes, I tried several things but it didn't work. Can you please show me an example based on my example code? "Btw noticed the nested operator classes in q code, is that working for you?". Yes for now, it is working!!! I also have some nested functions into a class which work. $\endgroup$ Commented Oct 19, 2020 at 10:06
  • $\begingroup$ I don't want redo panel to start from defaults. I just need a button (operator) which will reset all properties to their defaults values whenever user wants. $\endgroup$ Commented Oct 19, 2020 at 10:37
  • 1
    $\begingroup$ N which case Suggest making example code a minimum working example. ie imports and register $\endgroup$
    – batFINGER
    Commented Oct 19, 2020 at 10:38

1 Answer 1

8
$\begingroup$

Ditch your operator and use the one designed for this.

As a suggestion, add imports and register etc to question code, to make a minimal run-able example. This would only be a couple of lines and is appreciated by those answering not to have to do this themselves. (It adds up)

There is no need to re-invent the wheel and write a new nested operator to reset the defaults of another. Simply use the one designed to do this.

bpy.ops.wm.operator_defaults()

Set the active operator to its default values

eg in the layout of the operator to restore defaults.

layout.operator("wm.operator_defaults")

Would strongly consider looking at the 'PRESETS' system for operators, or using addon preferences to set and save preferences. Reset to defaults and settings prior are lost. Blender will start with the defaults.

As mentioned in comments the reset single or all to defaults is available via context menu (right click over property).

To have an operator always invoke with defaults see Force a Blender operator to always start with default values

$\endgroup$
2
  • $\begingroup$ Thank you one more time for the answer and all those useful information!!! And excuse me, next time where I'll ask something I will add a working example of code for sure. $\endgroup$ Commented Oct 19, 2020 at 11:17
  • $\begingroup$ Is there something similar for specific property and not for all properties into a redo panel? But as operator. Like the layout.operator("wm.operator_defaults"). $\endgroup$ Commented Oct 19, 2020 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .