Vertexgroups

Where does the vertex group store the indices from the vertices? or do the vertices know that they belong to a vertex group?

This goes for 2.5 to 2.62, not sure about 2.63 and up or 2.49 and lower.

To mess with vertex groups you need an Object and the Mesh. Mesh has a list of the verts in “Mesh.vertices” and each vert has a list of groups in “Vertex.groups” that lists the index of the groups that the vertex belongs to.

Once you have this index you look in “Object.vertex_groups[index]” to find the group that you are trying to access.

Another way to go is to find all the vertices that are in a given group. In that case you iterate “Object.vertex_groups” to find a group with the name that you want. This gives you the index of the group. Then you iterate Mesh.vertices looking for vertices that include that index as a group.

thx! very good explained. should go to the documentation!

list all vertices and there groups from the mesh and the list all the vertex_groups (index and name) from the object.

import bpy

obj = bpy.context.selected_objects[0]
mesh = obj.data

print("============================")

print("============= mesh.vertices:")

for i in mesh.vertices:
    print("Vertex: ", i.index)
    print("Groups: ", [j.group for j in i.groups])
    print("")

print("====== object.vertex_groups:")

for i in obj.vertex_groups:
    print("Vertex Groups: ", i.index, " (",i.name,")", sep="")

all verts from a given group:

group = "g3" # Fill in the group name
group_index = None

print()
print("All Vertices from the group ", group, ":", sep="")

for i in obj.vertex_groups:
    if i.name == group:
        group_index = i.index
        break

verts = []

for i in mesh.vertices:
    if group_index in [j.group for j in i.groups]:
        verts.append(i.index)

print(verts)