I am having trouble with the python code to get the colors of vertices when using Dynamic Paint. If I try painting a cube using the Vertex Paint mode I can get the rgb values of the vertices using the following code, however If I use Dynamic Paint to color the vertices I keep getting "None" for the color layer. Sorry if this is a newbie question but what am I doing wrong here? I thought the color data would be the same whether I used Dynamic Paint or Vertex Paint mode.

import bpy
import bmesh
context = bpy.context
scene = context.scene
mesh = context.object.data
bm = bmesh.new()

meshes = [o.data for o in scene.objects if o.type == 'MESH']
for mesh in meshes:
    color_layer = bm.loops.layers.color.get("Col")
    if color_layer is None:
        color_layer = bm.loops.layers.color.new("Col")
    for face in bm.faces:
        for loop in face.loops:
            print("Vert:", loop.vert.index)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.