I know this has been asked, but the answer form here: https://gist.github.com/tamask/2590850 doesn't work for me. I get an "out of range error" in the first loop. I tried modifying a solution from here: Vertices—loop indices vs. unique indices but nothing. Here's the code:

import bpy
from collections import defaultdict

obj = bpy.context.active_object
col = obj.data.vertex_colors.active
polygons = obj.data.polygons

color = (0, 1, 0, 0)

vertex_map = defaultdict(list)

for poly in polygons:
    for v_ix, l_ix in zip(poly.vertices, poly.loop_indices):
for v_ix, l_ixs in vertex_map.items():
    for l_ix in l_ixs:

        if col.data[l_ix].color == color:
            obj.data.vertices[v_ix].select = True

I would really appreaciate any help.


1 Answer 1


It is a comparison issue.

col.data[l_ix].color == color

You can:

from mathutils import Vector

color = Vector((0, 1, 0, 0))

Then compare with:

color == Vector(col.data[l_ix].color)

Alternatively, to avoid rounding issues, define an epsilon and compare using:

(color - Vector(col.data[l_ix].color)).length_squared < some_epsilon

You must log in to answer this question.

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