Relation Group.index/name vs ENUM in vertex_group_set_active

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

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

Relation Group.index/name vs ENUM in vertex_group_set_active

Post by anders211 » Tue May 07, 2013 10:21 pm

I would like to have max 4 bone influences per vertex. That is why I would like to get rid of weights which don't belong to 4 max weights. I wrote some python script which change all weights which aren't max 4 ones to 0. It works well. However now I have a problem because I would like to remove vertex groups with weight=0 in some way, however not from all groups, only specific ones. I see function vertex_group_clean with parameter all_groups:

bpy.ops.object.vertex_group_clean(limit=0.0, all_groups=False, keep_single=False)

If parameter 'all_groups' is False I suppose that vertex group which is active is cleared from those vertices for which weight is equal to 0.

The problem is how to set group to active one. There is function:

bpy.ops.object.vertex_group_set_active(group='')
Set the active vertex group
Parameters: group (enum in [], (optional)) – Group, Vertex group to set as active

but Blender design is very terrible because the argument is ENUM, not group id/name. For example I have group named "Head" which has id let's say 6. I got it from

Code: Select all

index = []
name = []
for Group in Object.vertex_groups:
name.append(Group.name)
index.append(Group.index)
I suppose that argument of vertex_group_set_active is not Group.index, because it is enum and we also have

bpy.ops.object.vertex_group_sort()
Sorts vertex groups alphabetically

So definitelly Group.index cannot be argument of vertex_group_set_active. I don't know who prepare such not friendly API interface. How can I get to know which enum corresponds to my Group.nam(index)????

Thanks for help

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

Post by CoDEmanX » Wed May 08, 2013 7:13 pm

what about the default op
bpy.ops.object.vertex_group_limit_total(limit=4, all_deform_weights=False)
?
I'm sitting, waiting, wishing, building Blender in superstition...

anders211
Posts: 0
Joined: Tue May 07, 2013 10:18 pm

Post by anders211 » Thu May 09, 2013 12:07 am

CoDEmanX wrote:what about the default op
bpy.ops.object.vertex_group_limit_total(limit=4, all_deform_weights=False)
?
I checked and it doesn't work. There are still some not removed bones weights with weight = 0.

Post Reply