How to get to know how much vertices is inside vertexGroup?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
anders211
Posts: 14
Joined: Tue May 07, 2013 10:18 pm

How to get to know how much vertices is inside vertexGroup?

Post by anders211 » Sat Nov 02, 2013 11:52 pm

I see bug in blender interface:
http://www.blender.org/documentation/bl ... ertexGroup

There is none way to get to know how much vertices are in this vertex group.

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Sun Nov 03, 2013 12:37 am

You can do that like:

Code: Select all

ob = bpy.context.object
vgroup_verts = {vgroup.name: [] for vgroup in ob.vertex_groups}

for v in ob.data.vertices:
    for g in v.groups:
        vgroup_verts[ob.vertex_groups[g.group].name].append(v.index)

for vgroup in vgroup_verts:
    vcount = len(vgroup_verts[vgroup])
    print("Vertex Group '%s' has %i %s." % (vgroup, vcount, "vertex" if vcount == 1 else "vertices"))
I'm sitting, waiting, wishing, building Blender in superstition...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests