1
$\begingroup$

I have assigned different materials to a single mesh. I want to create vertex groups from the materials assigned. Is it possible to create vertex groups from materials using python?

$\endgroup$
  • $\begingroup$ i see that you tagged "scripting".. do you mean that you wanna do It by code? or by 3D view? $\endgroup$ – Francesco Yoshi Gobbo Feb 22 '16 at 11:32
  • 1
    $\begingroup$ Yes how to do it through python code $\endgroup$ – ashwin Feb 22 '16 at 16:17
5
$\begingroup$

This script adds the verts assigned to the face assigned to a material to a vert group with the materials name.

import bpy
context = bpy.context
obj = context.active_object

for index, slot in enumerate(obj.material_slots):
    #select the verts from faces with material index
    if not slot.material:
        # empty slot
        continue
    verts = [v for f in obj.data.polygons 
           if f.material_index == index for v in f.vertices]
    if len(verts):
        vg = obj.vertex_groups.get(slot.material.name)
        if vg is None: 
            vg = obj.vertex_groups.new(name=slot.material.name)
        vg.add(verts, 1.0, 'ADD')
$\endgroup$
0
$\begingroup$

You can do it manually. Just hover over a vertex and click "l" and then f6 and choose material instead of seam or sharp.enter image description here

After that assign the selected vertices to a vertex group.

$\endgroup$
  • $\begingroup$ I am aware of this method thanks. I wanted to do it through script. $\endgroup$ – ashwin Feb 22 '16 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.