5

I wanted to know if it was possible, natively or with an addon, to make Blender auto create vertex groups when joining objects, by making each joined object a vertex group?

A concrete example:

  • I have a cube and a sphere.
  • I join them.
  • After joining them the new object has two vertex groups: one contains all vertices from the cube, the other all vertices from the sphere.

Is this a possible thing or do I need to manually make my groups before joining?

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
  • Hello, will you join the objects with CTRL J or with a boolean operation ? – Gorgious Jun 24 '20 at 11:55
  • 1
    Afaik, you need to make them manually. But for two objects, it would take me approx 12 seconds. Or are there other obstacles which you didn't mention? – Leander Jun 24 '20 at 12:34
  • Manually, but it might be slightly easier to join them first, then create the vertex groups. Because it's easier to select their respective vertices quickly in Edit Mode after the join is already complete. In Edit Mode, and while in vertex selection mode, press l (lowercase L) while your mouse cursor is floating over one of the joined counterparts, and all its vertices will be selected. Create your first vertex group. Then Ctrl + i to invert that selection. Now the other counterpart's vertices are selected. Create your second vertex group. – R-800 Jun 24 '20 at 12:45
  • Well I got a dozen objects that I want to join, so it's not impossibly long, but it'd still be easier if Blender had an auto way to do it XD

    Thanks for the advice, though I will be trying the script below first

    – Felina Faerlaingal Jun 24 '20 at 13:43

1 Answers1

5

Pre-op script

Testing shows that uniquely named vertex groups are retained when joining mesh objects. Instead of doing this manually (boring) can speed it up with a script.

Running script below will give each mesh object in selected objects a vertex group named after the object containing all verts with weight set to 1.

Have commented out the join operator, uncommenting will do it all in one, by running script when selection matches that for join. (ie adds selected to active)

import bpy

context = bpy.context

obs = [o for o in context.selected_objects if o.type == 'MESH']

for o in obs: vg = o.vertex_groups.new(name=o.name) vg.add(range(len(o.data.vertices)), 1.0, 'REPLACE')

run the operator

#bpy.ops.object.join()

It occurs that as well as adding vert group, renaming existing groups by for example prefixing object name would stop groups of same name merging

Add this in loop before making new group.

for vg in o.vertex_groups:
    vg.name = f"{o.name}_{vg.name}"

Deja Vu

Creating a batch version of a script that renames Vertex Groups

batFINGER
  • 84,216
  • 10
  • 108
  • 233