Assign custom properties for objects on the scene and display them in UI

Hi,
I’m a newbie in Python and Blender scripting and I need some help. I’m trying to create a blender addon that will for imported gltf/glb models collect all its objects, create for each custom property and display these properties inside a panel so the user can manually change its values. Here is what I have so far:


bl_info ={
    "name": "Flex Models Addon",
    "blender": (3,3,1),
    "category": "Object",
    "location": "Operator Search"
}

import bpy

# Global variables
PROPS = [
    ('object_id', bpy.props.StringProperty(name='Id')),
    ('object_name', bpy.props.StringProperty(name='Name')),
    ('object_is_resizable', bpy.props.BoolProperty(name='Is Resizable', default=False)),
    ('object_is_replaceable', bpy.props.BoolProperty(name='Is Replaceable', default=False)),
    ('object_has_materials', bpy.props.BoolProperty(name='Has Materials', default=False))]

class SCENE_PT_flex_models_options(bpy.types.Panel):
    bl_space_type = 'PROPERTIES'
    bl_region_type = "WINDOW"
    bl_category = "Flex"
    bl_label = "Flex Properties"
    bl_idname = "SCENE_PT_layout"
    bl_context = "object"
    
    def get_flex_objects(self):
        children = []
        myObject = bpy.data.objects['flex_root']

        for obj in bpy.data.objects: 
            if obj.parent == myObject: 
                children.append(obj)
        return children

    def draw(self, context):
        print("DRAW CALLED")
        layout = self.layout
        scene = context.scene
        test = context.object
        
        flex_objects = self.get_flex_objects()

        for obj in flex_objects:
            # Create a simple row.
            lbl = obj.name.replace("_", " ").capitalize()
            box = layout.box()
            row = box.row()
            row.prop(obj, "expanded",
                icon="TRIA_DOWN" if obj.expanded else "TRIA_RIGHT",
                icon_only=True, emboss=False
            )
            row.label(text=lbl)

            if obj.expanded:
                for (prop_name, _) in PROPS: 
                    row = box.row()        
                    # Assign custom properties to my object
def register():
    for (prop_name, prop_value) in PROPS:
        setattr(bpy.types.Scene, prop_name, prop_value)
    bpy.utils.register_class(SCENE_PT_flex_models_options)
    bpy.types.Object.expanded = bpy.props.BoolProperty(default=False)

def unregister():
    for(prop_name, _) in PROPS:
        delattr(bpy.types.Scene, prop_name)
    bpy.utils.unregister_class(SCENE_PT_flex_models_options)
    del bpy.types.Object.expanded

Welcome to BA :slight_smile: what do you need help with? You haven’t said what your problem is

Hi, sorry for the late replay. I manage to figure out this one myself :slight_smile: