0

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

mugnozzo
  • 1,237
  • 7
  • 21

2 Answers2

0

this answer is for vertex color of single object enter image description here

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')

  • Hello Seyed, I'm trying to use your script and keep getting this error with not much happening- Traceback (most recent call last): File "M:\3D\Jen_n_Tim\ShatteredMoon\ShatteredMoon_V2.Bake.blend\Text", line 10, in AttributeError: 'NoneType' object has no attribute 'vertex_colors' Error: Python script failed, check the message in the system console

    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
0

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')