Since Blender 2.9, the ability to assign color tags has been added for collections. Collection with such tag is displaying in a specific color in the outliner.
The collection color tag value is stored in its “color_tag” property. To change the color label of a collection, we need to assign a certain value to this property.
For example, to mark the current active collection in green:
1 |
bpy.context.collection.color_tag = 'COLOR_04' |
Or, to mark a collection by its name:
1 |
bpy.data.collections['Collection 10'].color_tag = 'COLOR_04' |
We can assign a color to a collection only from a limited set of colors. All possible color values we can get from its RNA structure:
1 2 3 4 |
tags = [item.identifier for item in bpy.context.collection.bl_rna.properties['color_tag'].enum_items] print(tags) # ['NONE', 'COLOR_01', 'COLOR_02', 'COLOR_03', 'COLOR_04', 'COLOR_05', 'COLOR_06', 'COLOR_07', 'COLOR_08'] |