I have an two mesh objects parented to the same parent, and I'd like to copy all the vertex groups from one object to the other (like using Transfer Weights with the Source being the "By Name"). This code fails with an "not correct context" or something (so I've got something wrongly selected):
ob = bpy.data.objects['New Mesh'] object = bpy.data.objects['CC_Base_Body'] for group in object.vertex_groups: bpy.ops.object.vertex_group_set_active(group=str(group.name)) vg = ob.vertex_groups.new(group.name)
Okay, I found some more information (and code) and it most likely will help a lot, but it does not do all the Transfer Mesh Data rollout does, which is to create the data by vertex mapping to the nearest vertex. Indeed, it immediately bails if the vertex counts aren't the same (which won't do at all). Here's the post with the code: https://stackoverflow.com/questions/40969164/how-to-add-vertex-groups-from-one-object-to-another-without-replacing-them
So, now I'm at the point of trying to figure out, from that code, how I can do that Vertex mapping to the nearest vertex, as the Transfer Mesh Data rollout allows (I will be on safe ground for the rest. as there are no vertex groups in the second mesh, so in creating them they will be brand new and empty).