Assign vertex color to multiple objects

Hi, I often need to assign some vertex colors to many objects in the scene.
2.8 allows for multi editing but vertex painting doesn’t work that way.
I don’t need to paint I just need to assign single color to a set of objects so that I don’t have to do that individually or merge objects into one…

Thanks for any help

This sets vertex colors for all objects based on the active object. If you want to pick a manual color for whole selection, set color_from_active to False and set the color you want.

from bpy import context

def color_from_active():
    active = context.active_object
    selection = context.selected_objects
    objs = [o for o in selection if not o is active and o.type == 'MESH']
    
    if not objs or not 'OBJECT' in context.mode:
        print("No selection")
        return

    # set to True to use color from active (assumes any vertex is colored)
    color_from_active = True

    # or use a solid color (r,g,b,a)
    color = [0,0,1,1]

    if color_from_active:
        if active.data.vertex_colors:
            v_col = active.data.vertex_colors[0]
            color = list(v_col.data[0].color)
    else:
        objs.append(active)
            
    if objs:
        for o in objs:
            if not o.data.vertex_colors:
                v_col = o.data.vertex_colors.new()
                
            else:
                v_col = o.data.vertex_colors[0]
                
            for data in v_col.data:
                data.color = color
        
if __name__ == "__main__":
    color_from_active()

Oh boy, this just might be exactly what I’m looking for :slight_smile:

Thank You

Forget it: it does work straight out of the box!