1
$\begingroup$

I'm surprised that I can not find an answer to this one. Is there any way to restore a specific add-on's preference states to the defaults?

I would prefer not to uninstall the add-on if possible.

$\endgroup$
2
$\begingroup$

You can create an Operator and make it part of the Preferences layout for your custom add-on:

class MyAddonPreferences(bpy.types.AddonPreferences):

    bl_idname = __name__

    display_flag: bpy.props.BoolProperty(
            name="Display Flag",
            default = True)

    def draw(self, context):
          ...
          layout.row().operator("my_addon.reset_preferences")

Best practice is using property_unset(property):

class MYADDON_OT_resetPreferences(bpy.types.Operator):
    """ Reset Add-on Preferences """
    bl_idname = "my_addon.reset_preferences"
    bl_label = "Reset Properties and Settings"
    bl_options = {"INTERNAL"}

    def execute(self, context):
        prefs = context.preferences.addons[__name__].preferences
        prefs.property_unset("display_flag")
        ...
        return {'FINISHED'}

In order to reset the properties of a certain add-on it's basically the same, you just need to find a way getting the name of each property.

Example on how to reset the settings of Loop Tools by reading its annotations using the Console:

>>> prefs = C.preferences.addons['mesh_looptools'].preferences
>>> props = prefs.__annotations__.keys()
>>> for p in props:
...     prefs.property_unset(p)
$\endgroup$
  • $\begingroup$ So essentially call property_unset() for each preference variable? This is really useful, thank you. What about from a user's perspective - a user wanting to clear an add-on's preferences without scripting? I haven't experimented much with this, but how would they usually go about doing this? Is there a folder or file where these settings are saved per-project? Thanks again! $\endgroup$ – Robert Sep 16 '19 at 17:34
  • $\begingroup$ There is no generic option for the user atm, you have to provide that @Robert $\endgroup$ – brockmann Sep 16 '19 at 18:17

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.