1
$\begingroup$

Now that we have a dedicated panel for the Collections properties in the properties editor, I was hoping we could access a collection's custom properties interface like we can for the other objects in the other panels. However this is not available.

enter image description here

See for example the object properties :

enter image description here

How can I have access to the collection custom properties using only the interface ?

$\endgroup$

1 Answer 1

3
$\begingroup$

EDIT : Starting with Blender 3.3 this feature is in Blender by default. There is no need anymore to create a custom python addon.


For Blender up to 3.2 :

As you may know in Blender, all objects inheriting from ID (Object) can hold custom properties. These are useful to store specific bits of information on objects. They can be accessed in many parts of Blender, and by the python API.

The Collection types inherits from ID, so it supports custom properties.

This means we can add, read and delete custom properties on collections using the python API.

import bpy

collection = bpy.data.collections["Collection"]
collection["prop"] = 2
print(collection["prop"])
del(collection["prop"])

Are all supported.

However the interface doesn't allow us to have a direct access to these properties without using the API.

Thankfully we can re-use a built-in construct to provide this behaviour in a very low amount of code. We're going to write a script that can be imported as an add-on so the functionality is always available.

import bpy
from rna_prop_ui import PropertyPanel


bl_info = {
    "name": "Collection Custom Properties",
    "blender": (2, 80, 0),
    "category": "Interface",
    "version": (1, 0, 0),
    "author": "Gorgious56",
    "description": "Access Collection Custom Properties",
}


class GU_PT_collection_custom_properties(bpy.types.Panel, PropertyPanel): 
    _context_path = "collection"
    _property_type = bpy.types.Collection
    bl_label = "Custom Properties"
    bl_idname = "GU_PT_collection_custom_properties"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "collection"


def register():
    bpy.utils.register_class(GU_PT_collection_custom_properties)


def unregister():
    bpy.utils.unregister_class(GU_PT_collection_custom_properties)


if __name__=="__main__":
    register()

Write this into a text file with your favorite notepad, then save & quit. Change the extension to .py. Your file should look like this :

enter image description here

Now go to Edit > Preferences > Add-on > Install and navigate to your file, click on "Install Add-on" and check the box in the new entry.

enter image description here

Result :

enter image description here

Credits to @Wahooney on Blenderartists : https://blenderartists.org/t/collections-with-custom-attributes/1142437/12

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .