Using add-on preferences
Besides using Blender preferences, we can use bpy.types.AddonPreferences
to display the add-on-specific custom settings under the add-on activation checkbox. It’s an interface, just like bpy.types.Panel
, and we can add settings to its layout using its draw
method.
The bl_idname
attribute of AddonPreferences
must match the Python name of the add-on. The usage of __name__
for single files and __package__
for folders makes our code easier to maintain: these variables always match the respective Python names, so changes in files and folders’ names would have no consequences.
Creating preferences
Since we are using multiple files, we will create preferences.py
inside the folder of our structured_addon
. It contains the StructuredPreferences
class:
import bpy class StructuredPreferences(bpy.types.AddonPreferences
): bl_idname =__package__
def draw(self, context): ...