Select Objects by Color Attribute

Hi!

Is there a way to select objects by their color attributes? I often work with CAD data, where the material assignment is based on this attribute.
Attached is a small example.

select_display_color.blend (911.0 KB)

You could use geonodes to separate those by attributes.

Hope that helps

1 Like

Thanks but the problem is I have to have a real selection of the objects in the outliner to apply materials.

Ok, maybe you should explain exactly what you are looking for…

You want to assign some materials? or change materials? but based on material colour?

Imagine to have a complex cad file that consist of thousend of objects grouped in maybe hundreds of emptys in a hierachy and the only information I have for assigning different materials or select certain objects to move them arround or put in collections is their color attribute.
Hope that explanation helps a bit.

Hello…

In Object mode: There is no way to select objects based on Attributes that are not Object-level… i.e. you can change Viewport Display Color
image
and select by that (Select → Grouped → Color).

In Edit mode: Selecting by vertex color in Edit mode makes sense but there is no feature to help with that that I know of… just being able to edit multiple objects concurrently is a relatively new feature and you may have to resort to writing a custom script to achieve what you’re after, sorry.

BTW: Blender 4.0 has edit-mode features coupled with selection in GN and a greater focus on custom attributes so that may solve your issue but in the meantime scripts may be your only option.

Good luck.

1 Like

nezumi.blend came up with a script that makes a selection depending on the color of the first vertex in a color attribute and solved my problem.

Just select one object with the color you want to select and run the script in the Scripting tab.

import bpy
from mathutils import Vector

obj = bpy.context.object
ref_col = None

# verify original active object has color attribute
try:
    col = obj.data.color_attributes.active_color
    ref_col = Vector(col.data[0].color)
except AttributeError:
    pass

if ref_col:
    for ob in bpy.data.objects:
        try:
            if Vector(ob.data.color_attributes.active_color.data[0].color) == ref_col:
                ob.select_set(True)
        except AttributeError:
            pass
1 Like

I tried to run this script, but got an error. Is this able to work if I have a single mesh that has a color attribute, and I want to easily select all the faces that have ? Error:

Python: Traceback (most recent call last):
  File "C:\Users\████\Documents\Balmore.blend\Text", line 10, in <module>
IndexError: bpy_prop_collection[index]: index 0 out of range, size 0

It is made to select whole objects not faces, so it probably won’t work.