Reader small image

You're reading from  Python Scripting in Blender

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781803234229
Edition1st Edition
Right arrow
Author (1)
Paolo Acampora
Paolo Acampora
author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora

Right arrow

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):
     ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Python Scripting in Blender
Published in: Jun 2023Publisher: PacktISBN-13: 9781803234229

Author (1)

author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora