How to rename a vertex group ?

I can create a new vertex group so:
bpy.ops.object.vertex_group_assign(new=True)

That gives it a default name: how do I give to that group a name that isn’t the default?

Thanks.

I found this:


meshes<i>.vertex_groups['Group'].name=meshes[i].name

In context: my script allows to give to a vertex group of all vertices in an object the name of that object, for each mesh object in a selection of objects.
Then I join the objects into a single one for editing.
When finished, I hope that another script will allow to separate the edited mesh into its original objects.

Very W.I.P. as you can see. :slight_smile:


[I]#FILTER OUT NON-MESHES
#collect the selected mesh objects in a list</i>
meshes=[]
collection=bpy.context.selected_objects

for obj in range (0, len(collection)):
    if collection[obj].type=='MESH':
        meshes.append(collection[obj])
        

<i>#MAKE VERTEX_GROUPS</i>
for i in range(0,len(meshes)):
    <i>#make one object active</i>
    bpy.context.scene.objects.active=meshes<i>
    [I]#take note of its name</i>
    name=meshes<i>.name
    [I]#go into edit mode</i>
    bpy.ops.object.mode_set(mode='EDIT') 
    <i>#select all its vertices</i>
    bpy.ops.mesh.select_all(action='SELECT')
    <i>#make one vertex_group (aka 'VG')with them</i>
    bpy.ops.object.vertex_group_assign(new=True)
    <i>#name it the same as the object</i>
    <b>meshes<i>.vertex_groups['Group'].name=meshes[I].name</i></b>
    <i>#reset mode to get appropriate context</i>
    bpy.ops.object.mode_set(mode='OBJECT')