# Imported OBJ Groups to Vertex Groups

I have an OBJ file for a character, which I have divided into groups (left hand, right leg, etc).

I have imported it with separate objects for each group. I can get rid of the seams and all the groups with the join command (Ctrl + J), but then there are no vertex groups. Which I need for rigging. (I know there are other ways I can make vertex groups, just pretend I need them based on this OBJ file's groups.)

What is the fastest, most efficient way to convert all these separate objects into one object with vertex groups named with the separate object names? is there a magic script/button for that?

## 1 Answer

You can write a script to create the groups with all the vertecies in one group for each mesh and then just join it.

I just quickly threw this together. I don't usually write much python, so don't confuse this with good code (I'm sure some list comprehensions could clean this up nicely).

import bpy;

selected = bpy.context.selected_objects
print(selected)
selected_meshes = []

# only use meshes of the selected objects
for obj in selected:
if obj.type == 'MESH':
selected_meshes.append(obj)

# for each mesh make a vertex group with all vertices in it
for obj in selected_meshes:
vg = obj.vertex_groups.new(obj.name)
verts = []
for vt in obj.data.vertices:
verts.append(vt.index)
vg.add(verts,1.0,"ADD");

# join meshes
if len(selected_meshes) > 0:
# copy selection to new context to avoid messing with selection of the current scene
ctx = bpy.context.copy()
ctx['active_object'] = selected_meshes[0]
ctx['selected_objects'] = selected_meshes
# this was jsut copypasta from here: https://blender.stackexchange.com/questions/13986/how-to-join-objects-with-python
ctx['selected_editable_bases'] = [bpy.context.scene.object_bases[ob.name] for ob in selected_meshes]
bpy.ops.object.join(ctx)