how to create vertex groups from materials using python? 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?
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')