Vertex blend indices and blend weights

I’ve been reading through the python API for hours, but I can’t figure out how I can get the blend indices and blend weights for a vertex. I have an exporter that writes all the skeleton information right now, but I need to be able to export indices and weights for each bone. Where can I access those? Does Blender even store them in a format that would be easy to convert to indices and weights?

The weights are stored in the vertex groups:

import bpy

ob = bpy.context.object
me = ob.data

vgroups = {i: vgroup.name for i, vgroup in enumerate(ob.vertex_groups)}

for v in me.vertices:
    print("Vertex %i" % v.index)
    for group in v.groups:
        print("  %s = %f" % (vgroups[group.group], group.weight))

Okay. How do the weights correspond to the bone indices though? It looks like the second part is the indices for vertex index buffers, but I need to be able to get the bone index that a specific group is influenced by.

Code looks slightly different for this:

"""
Data structure is a dict of dicts,
the outer dict uses bone indices as keys
and the values are dicts with keys being vertex indices
and values vertex weights:
    
weights = {
    1: {
        0: 0.7,
        1: 0.2,
        4: 0.1,
    },
    2: {
        2: 0.8,
        4: 0.2,
    }
}

"""
print("-"*30)

import bpy

ob = bpy.context.object
me = ob.data

weights = {}

for v in me.vertices:
    for group in v.groups:
        weights.setdefault(group.group, {})[v.index] = group.weight
        
for bone_index, vertex_weights in weights.items():
    print("
Bone %i (%s)" % (bone_index, ob.vertex_groups[bone_index].name))
    for vert_index, vert_weight in sorted(vertex_weights.items(), key=lambda x: x[1], reverse=True):
        print("   Vertex %i = %f" % (vert_index, vert_weight))

Bone index = vertex group index. Above code prints vertex weights sorted by influence (descending).

Okay. Thanks, this should work perfectly.

sorry for reviving this thread after several years… do you know if it’s possible to print vertex weights and vertex coordinates of any given selection of vertexes in edit mode?I would like to print data related to vertex groups, sorry again, i saw this thread and it’s very close to what i was looking for.