0

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): vertex_map[v_ix].append(l_ix)

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.

  • https://blender.stackexchange.com/questions/73846/how-to-compare-colour-values-in-blender-using-python – batFINGER Dec 08 '20 at 07:09

1 Answers1

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
lemon
  • 60,295
  • 3
  • 66
  • 136