How to print/access vertex color data?

Hello All,

For a work project, I’m looking to access the RGB vertex color data directly, so that I can analyze the color data externally. I’m sure there’s a way to ‘print’ the data through the console, I just have no idea how. If there’s a way to export just the vetex color data to a simple notepad file or something like that that would be awesome. Any help or suggestions super appreciated it.

Basically, I’d love to find a script or addon that ‘prints’ the vertex color data for an object. How do I access that information?

Thank you all very much:D

Hi, you could use this little script (i just wrote, :slight_smile: )
Maybe this can be done even simpler…
Just make your object active, load this script into blender (as Text) and do “Run Script”… this will print out the color values on console.
Note, vertex color data is readonly if accessed this way (i think, could be wrong…)


import bpy

ob = bpy.context.object

#vertex colors are in fact stored per loop-vertex -> MeshLoopColorLayer
if ob.type == 'MESH':
    #how many loops do we have ?
    loops = len(ob.data.loops)
    verts = len(ob.data.vertices)
    visit = verts * [False]
    colors = {}
    #go through each vertex color layer
    for vcol in ob.data.vertex_colors:
        # look into each loop's vertex ? (need to filter out double entries)
        for l in range(loops):
            v = ob.data.loops[l].vertex_index
            c = vcol.data[l].color
            if not visit[v]:
                colors[v] = c
                visit[v] = True
                
    sorted(colors)
    print("Colors by Vertex:")
    #print(colors)
    for v, c in colors.items():
        print("Vertex {0} has Color {1}".format(v, (c.r, c.g, c.b)))
                

Edit: Rather try this… i did not take multiple vertex colors into account previously…


import bpy

ob = bpy.context.object

#vertex colors are in fact stored per loop-vertex -> MeshLoopColorLayer
if ob.type == 'MESH':
    
    #how many loops do we have ?
    loops = len(ob.data.loops)
    verts = len(ob.data.vertices)
   
    #go through each vertex color layer
    for vcol in ob.data.vertex_colors:
        # look into each loop's vertex ? (need to filter out double entries)
        visit = verts * [False]
        colors = {}
        
        for l in range(loops):
            v = ob.data.loops[l].vertex_index
            c = vcol.data[l].color
            if not visit[v]:
                colors[v] = c
                visit[v] = True
                
        sorted(colors)
        print("Vertex-Colors of Layer:", vcol.name)
        #print(colors)
        for v, c in colors.items():
            print("Vertex {0} has Color {1}".format(v, (c.r, c.g, c.b)))
            
        print("
")
                

1 Like

The vertex painted values are correctly printing. How can I get the dynamic painted values