BlenderConfigSet

February 7, 2026 · View on GitHub

Overview

BlenderConfigSet is the primary concrete implementation of ConfigurationSet, designed to manage configuration settings by storing them as Blender properties on entity types. It bridges the gap between MPFB's configuration system and Blender's property system, allowing settings to be stored directly on scenes, objects, or other Blender data types.

The class supports multiple property types matching Blender's property system: booleans, strings, integers, floats, enums, colors, vectors, and file/directory paths. Properties can be defined either programmatically or loaded from JSON definition files, making it easy to declare large sets of configuration options.

Each BlenderConfigSet is bound to a specific Blender type (e.g., bpy.types.Scene or bpy.types.Object) and uses a configurable prefix to namespace its properties. For example, a config set with prefix "modeling_" on bpy.types.Scene would create properties like MPFB_modeling_detail_level. This prevents naming collisions between different MPFB subsystems.

The class also provides UI integration through draw_properties(), which renders properties directly in Blender panels with proper labels and formatting. It supports property aliases for backwards compatibility when property names change.

Source

src/mpfb/services/blenderconfigset.py

Dependencies

DependencyUsage
LogServiceLogging via LogService.get_logger("configuration.blenderconfigset")
ConfigurationSetAbstract base class

Property Types

Properties are defined as dictionaries with these fields:

FieldRequiredDescription
nameYesShort name (identifier)
typeYesProperty type (see below)
descriptionYesHelp text shown in UI
defaultYesDefault value
itemsEnum onlyList of [identifier, name, description] tuples
min / maxFloat onlyValue range constraints
aliasesNoAlternative names for backwards compatibility
labelNoDisplay name in UI (defaults to name)
subtypeNoSpecial rendering (e.g., "panel_toggle" for booleans)

Supported types:

  • booleanBoolProperty
  • stringStringProperty
  • pathStringProperty with FILE_PATH subtype
  • dir_pathStringProperty with DIR_PATH subtype
  • intIntProperty
  • floatFloatProperty with optional min/max
  • vector_locationFloatVectorProperty (3D XYZ)
  • colorFloatVectorProperty (4-component RGBA, 0.0–1.0)
  • enumEnumProperty

Public API

Constructor

BlenderConfigSet(properties, bpy_type, prefix="", *, lowercase_prefix=False, getter_factory=None, setter_factory=None)

Create a new configuration set.

ArgumentTypeDefaultDescription
propertieslist[dict]List of property definitions
bpy_typetypeBlender type to attach properties to (e.g., bpy.types.Scene)
prefixstr""Prefix added after MPFB_
lowercase_prefixboolFalseUse lowercase mpfb_ prefix
getter_factorycallableNoneFactory function for custom getters
setter_factorycallableNoneFactory function for custom setters

Static Methods

get_definitions_in_json_directory(properties_dir)

Read property definitions from all JSON files in a directory.

ArgumentTypeDefaultDescription
properties_dirstrDirectory containing JSON definition files

Returns: list[dict] — List of property definitions.

Raises: IOError — If a JSON file cannot be read.


Instance Methods

get_type()

Return the Blender type this configuration set manages.

Returns: type — The bpy.types class (e.g., bpy.types.Scene).


get_fullname_key_from_shortname_key(key_name)

Construct the full property name from a short name.

ArgumentTypeDefaultDescription
key_namestrShort property name

Returns: str — Full property name with prefix (e.g., "MPFB_modeling_detail_level").


check_and_transform_entity_reference(entity_reference)

Validate that an entity reference matches the expected Blender type.

ArgumentTypeDefaultDescription
entity_referenceanyThe entity to validate

Returns: The validated entity reference.

Raises: ValueError — If the reference is None or wrong type.


get_value(name, default_value=None, entity_reference=None)

Retrieve the value of a property from a Blender entity.

ArgumentTypeDefaultDescription
namestrProperty name (short or full)
default_valueanyNoneValue if property not found
entity_referenceanyBlender entity to read from

Returns: The property value or default_value.

Accepts short names, full names, or aliases.


set_value(name, value, entity_reference=None)

Set the value of a property on a Blender entity.

ArgumentTypeDefaultDescription
namestrProperty name (short or full)
valueanyValue to set
entity_referenceanyBlender entity to modify

Raises: ValueError — If the property doesn't exist.

Also updates any aliases defined for the property.


get_keys()

Retrieve all short property names.

Returns: dict_keys — View of short property names.


has_key(name)

Check if a property exists.

ArgumentTypeDefaultDescription
namestrProperty name (short, full, or alias)

Returns: boolTrue if property exists.


has_key_with_value(name, entity_reference=None)

Check if a property exists and has a non-null value.

ArgumentTypeDefaultDescription
namestrProperty name
entity_referenceanyEntity to check

Returns: boolTrue if property has a value.


add_property(prop, items_callback=None, override_prefix=None)

Add a new property to the configuration set.

ArgumentTypeDefaultDescription
propdictProperty definition dictionary
items_callbackcallableNoneDynamic items function for enums
override_prefixstrNoneUse this prefix instead of the default

Registers the property on the Blender type and tracks it internally.


draw_properties(entity_reference, component_to_draw_on, property_names, *, text=None, **kwargs)

Draw properties on a Blender UI component.

ArgumentTypeDefaultDescription
entity_referenceanyEntity with the properties
component_to_draw_onUILayoutBlender layout to draw on
property_nameslist[str]Properties to draw
textstrNoneOverride label for all properties
**kwargsAdditional args passed to layout.prop()

Raises: ValueError — If entity or component is None.

Special handling for panel_toggle subtype booleans (shows collapse arrows).


deferred_draw_property(entity_reference, component_to_draw_on, property_name, text=None)

Draw a property not known to the config set.

Override this in subclasses to handle dynamic properties.


get_property_id_for_draw(name)

Get the full property name for direct layout.prop() calls.

ArgumentTypeDefaultDescription
namestrShort property name

Returns: str or None — Full property name, or None if not found.


Examples

Creating a Configuration Set from JSON

from mpfb.services.blenderconfigset import BlenderConfigSet
import bpy

# Load property definitions from a directory
props = BlenderConfigSet.get_definitions_in_json_directory("/path/to/props")

# Create config set for scene storage
config = BlenderConfigSet(props, bpy.types.Scene, prefix="modeling_")

Defining Properties Programmatically

from mpfb.services.blenderconfigset import BlenderConfigSet
import bpy

properties = [
    {
        "name": "detail_level",
        "type": "int",
        "description": "Level of mesh detail",
        "default": 3
    },
    {
        "name": "use_smoothing",
        "type": "boolean",
        "description": "Apply smoothing to mesh",
        "default": True
    },
    {
        "name": "render_mode",
        "type": "enum",
        "description": "Rendering mode",
        "default": "SOLID",
        "items": [
            ["SOLID", "Solid", "Solid shading"],
            ["WIREFRAME", "Wireframe", "Wireframe view"],
            ["TEXTURED", "Textured", "Full textures"]
        ]
    }
]

config = BlenderConfigSet(properties, bpy.types.Scene, prefix="render_")

Using the Configuration Set

# Set a value
config.set_value("detail_level", 5, entity_reference=bpy.context.scene)

# Get a value
level = config.get_value("detail_level", entity_reference=bpy.context.scene)

# Check if property exists
if config.has_key("use_smoothing"):
    smoothing = config.get_value("use_smoothing", entity_reference=bpy.context.scene)

Drawing in a Panel

class MY_PT_Panel(bpy.types.Panel):
    bl_label = "My Settings"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'

    def draw(self, context):
        layout = self.layout
        config.draw_properties(
            context.scene,
            layout,
            ["detail_level", "use_smoothing", "render_mode"]
        )

Property Definition JSON File

{
    "name": "skin_color",
    "type": "color",
    "description": "Base skin color for the character",
    "default": [0.8, 0.6, 0.5, 1.0],
    "label": "Skin Color"
}