I’ve created this tread on Blender Stack Exchange but thought others here might want to know or contribute to the discussion.
https://blender.stackexchange.com/questions/137675
Current Code is
import bpy
vgname1 = 'Leg_L'
vgname2 = 'LegD3_L'
vgi1 = -1
vgi2 = -1
vvgi1 = -1
vvgi2 = -1
verts=[]
vWeight=[]
#Get current mode and name for active object
mode = bpy.context.active_object.mode
obname = bpy.context.active_object.name
print(mode, obname)
#Walk through Vertex Groups and determine if the New Group
#already exists, if not, create the new Group Also Get the
#index numbers for the 2 Groups in question
for ob in bpy.data.objects:
if ob.name == obname:
for vgn in ob.vertex_groups:
if vgn.name == vgname1:
vgi1 = vgn.index
if vgn.name == vgname2:
vgi2 = vgn.index
if vgi2 == -1:
ob.vertex_groups.new(name=vgname2)
for vgn2 in ob.vertex_groups:
if vgn2.name == vgname2:
vgi2 = vgn2.index
#Test the results
print( ob.name, vgname1,vgi1, vgname2, vgi2)
#Put the object into Object Mode and get the
#vertexes that are currently assigned to the group to be removed
#Put the vertex indexes to be moved into a list
bpy.ops.object.mode_set(mode = 'OBJECT')
for v in bpy.context.active_object.data.vertices:
for vg in v.groups:
if vg.group == vgi1:
print(vg.group, vg.weight)
verts.append(v.index)
#Ignore vWeight = vg.weight
#Now add the vertexes to the other group
vg2 = ob.vertex_groups
for vga in vg2:
if vga.index == vgi2:
print(vga.index,vga.name)
vga.add(verts, 0, 'ADD')