How can I set my favorite color to all of the selected objects?
I can't attach my objects not at all.
The number of objects is high and I can not adjust their color vertex one by one.
Sorry for my bad english.
Thanks
How can I set my favorite color to all of the selected objects?
I can't attach my objects not at all.
The number of objects is high and I can not adjust their color vertex one by one.
Sorry for my bad english.
Thanks
this answer is for vertex color of single object

I converted it to multiple objects:
import bpy
import random
import time
# start in object mode
objects = bpy.context.scene.objects
for obj in objects:
mesh = obj.data
if not mesh.vertex_colors:
mesh.vertex_colors.new()
color_layer = mesh.vertex_colors["Col"]
# or you could avoid using the color_layer name
# color_layer = mesh.vertex_colors.active
i = 0
for poly in mesh.polygons:
for idx in poly.loop_indices:
color_layer.data[i].color = (0, 1, 0, 1)
i += 1
# set to vertex paint mode to see the result
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
The answer from Seyed changes the vertex color of all scene objects. This script changes only the selected objects:
import bpy
import random
import time
start in object mode
bpy.ops.object.mode_set(mode='OBJECT')
get selected objects
objects = bpy.context.selected_objects
for obj in objects:
mesh = obj.data
if not mesh.vertex_colors:
mesh.vertex_colors.new()
color_layer = mesh.vertex_colors["Col"]
# or you could avoid using the color_layer name
# color_layer = mesh.vertex_colors.active
i = 0
for poly in mesh.polygons:
for idx in poly.loop_indices:
color_layer.data[i].color = (1, 0, 1, 1)
i += 1
# set to vertex paint mode to see the result
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
Any ideas, or does it not work in Blender 2.92? I tried with both mesh.vertex_colors.new() and mesh.vertex_colors.active same result.
– MarkS Apr 10 '21 at 22:24