posted an update

Code for blender script:

import bpy import bmesh

LAYER_NAME = "Col" # vertex color layer name to write

def get_base_color(mat): """Return (None, solid_color) from Principled BSDF Base Color (unlinked), else bright pink.""" fallback_color = (1.0, 0.0, 1.0, 1.0) if not mat or not getattr(mat, "use_nodes", False) or not getattr(mat, "node_tree", None): return None, fallback_color

for node in mat.node_tree.nodes:
    if getattr(node, "type", None) == 'BSDF_PRINCIPLED':
        base_input = node.inputs.get("Base Color")
        if base_input and not base_input.is_linked:
            color = base_input.default_value
            if color and len(color) >= 3:
                return None, (color[0], color[1], color[2], color[3] if len(color) > 3 else 1.0)
return None, fallback_color

def bake_obj_to_vertex_colors(obj): if obj is None or obj.type != 'MESH': return False, f"Skipped: {obj.name if obj else 'None'} (not a mesh)"

mesh = obj.data
bm = bmesh.new()
bm.from_mesh(mesh)

# Get/create BMesh loop color layer explicitly
vcol_layer = bm.loops.layers.color.get(LAYER_NAME)
if vcol_layer is None:
    vcol_layer = bm.loops.layers.color.new(LAYER_NAME)

mat_slots = obj.material_slots
material_cache = {}

for face in bm.faces:
    mi = face.material_index
    mat = mat_slots[mi].material if mi < len(mat_slots) else None
    if mat not in material_cache:
        material_cache[mat] = get_base_color(mat)
    _, solid_color = material_cache[mat]
    color = solid_color or (1.0, 0.0, 1.0, 1.0)

    for loop in face.loops:
        loop[vcol_layer] = (color[0], color[1], color[2], color[3])

bm.to_mesh(mesh)
bm.free()

# Try to mark the new/updated color attribute active in 4.x+
try:
    if hasattr(mesh, "color_attributes") and LAYER_NAME in mesh.color_attributes:
        mesh.color_attributes.active_color = LAYER_NAME
except Exception:
    pass

mesh.update()
return True, f"Baked: {obj.name}"

def bake_selected(): sel = bpy.context.selected_objects or [] if not sel: print("Nothing selected.") return

print(f"Vertex color bake on {len(sel)} selected objects...")
results = []
for obj in sel:
    ok, msg = bake_obj_to_vertex_colors(obj) if obj.type == 'MESH' else (False, f"Skipped: {obj.name} (not a mesh)")
    results.append(msg)
    print(msg)

print("Done.")
# Optional: report summary in the status bar
#bpy.ops.wm.report(type={'INFO'}, message="; ".join(results)[:1024])

Run on the current selection

bake_selected()

Log in or sign up for Devpost to join the conversation.