How to get preset paths in Blender Python

This is a tips for blender addon developers.

GOAL

To get the list of paths to preset directories, blender system preset and user preset and so on.

These are examples of the preset directory.

  • presets of interface theme
    • C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\presets\interface_theme
    • C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\addons\presets\interface_theme’
  • presets of keyconfig
    • C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\presets\keyconfig
    • C:\Users\<USER_NAME>\AppData\Roaming\Blender Foundation\Blender\2.83\scripts\presets\keyconfig

Environment

Blender 2.83 (Python 3.7.4)
Windows 10

Method

Use bpy.utils.preset_paths(subdir) that returns the list of paths to the preset directory of subdir.

You can see the subdirs in the presets directory “C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\presets”

Examples

print(bpy.utils.preset_paths("interface_theme"))
# output => ['C:\\Program Files\\Blender Foundation\\Blender 2.83\\2.83\\scripts\\presets\\interface_theme', 'C:\\Program Files\\Blender Foundation\\Blender 2.83\\2.83\\scripts\\addons\\presets\\interface_theme']
print(bpy.utils.preset_paths("render"))
# output => ['C:\\Program Files\\Blender Foundation\\Blender 2.83\\2.83\\scripts\\presets\\render']
print(bpy.utils.preset_paths("nothing"))
# output => []