# Batch Delete Vertex Groups script

**URL:** <https://blenderartists.org/t/batch-delete-vertex-groups-script/449881>\
**Category:** Python Support\
**Created:** [June 9, 2009, 7:43am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881 "2009-06-09T07:43:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ave](https://blenderartists.org/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@ave](https://blenderartists.org/u/ave)\
**Post date:** [June 9, 2009, 7:43am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/1 "2009-06-09T07:43:39Z")

</div>

Here is a quick script I did to quickly delete a few vertex groups at once

very simple to use, just run the script.  
a screen will appear listing all the vertex groups, select the ones you want to delete and press the delete button  
thats it…

```auto

#!BPY
"""
Name: 'Delete Vertex Groups'
Blender: 248
Group: 'Mesh'
Tooltip: 'Batch Delete Vertex Groups'
"""

__author__ = "Brad Gonsalves AKA AVE"
__url__ = ["blenderartists.org", "www.blender.org"]
__version__ = "1.0 2009/06/09"

# -------------------------------------------------------------------------- 
# *****BEGIN GPL LICENSE BLOCK***** 
# 
# This program is free software; you can redistribute it and/or 
# modify it under the terms of the GNU General Public License 
# as published by the Free Software Foundation; either version 2 
# of the License, or (at your option) any later version. 
# 
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU General Public License for more details. 
# 
# You should have received a copy of the GNU General Public License 
# along with this program; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
# 
# *****END GPL LICENCE BLOCK***** 
# --------------------------------------------------------------------------

import Blender
from Blender import Draw, BGL, Scene, Mesh, Window, sys, Object

import bpy

GroupList=[]
ToggleState=[]
VGListRunning=1
co=[0,0]
GEventNumBase=20
VGColumns=4
GError=False

scn = Scene.GetCurrent()
obj= scn.getActiveObject()

if obj.getType()!='Mesh':
    obj= None
    
sel= [ob for ob in Object.GetSelected() if ob.getType()=='Mesh' if ob != obj]
if not sel and not obj:
    Draw.PupMenu('Error, select a mesh as your active object')
    GError=True
else:
    me = obj.getData(mesh=1) 
    
    InEditMode = Window.EditMode()    
    
    co=Window.GetMouseCoords()

    Window.EditMode(0)
    Window.EditMode(1)

def ToggleButton(event, val):
    global ToggleState
    global VGListRunning
    Found=False
    for x in ToggleState:
        if x[0]==event:
            Found=True
            x[1]=val
    if Found==False:
        ToggleState.append([event,val])
    VGListRunning=1

def FindToggleState(event):
    Found=False
    for x in ToggleState:
        if x[0]==event:
            Found=True
            return(x[1])
    if Found==False:
        return(0)

def DeleteVGroups(event, val):
    global VGListRunning
    Window.EditMode(0)
    if event==1:
        EventNum=GEventNumBase
        for x in GroupList:
            Toggle=FindToggleState(EventNum)
            if Toggle:
                me.removeVertGroup(x)
            EventNum+=1
    VGListRunning=0

def buttons():
    global GroupList
    global co
    global VGListRunning
    global GEventNumBase
    
    ColHeight=20
    ColWidth=105
    
    GroupList=me.getVertGroupNames()
    
    EventNum=GEventNumBase
    if len(GroupList)&lt;VGColumns:
        CenWidth=0
        CenHeight=0
    else:
        CenWidth=(VGColumns*ColWidth)/2
        CenHeight=((len(GroupList)/VGColumns)*ColHeight)/2
    
    BaseCoX=co[0]-CenWidth
    BaseCoY=co[1]+CenHeight
    coY=BaseCoY
    coX=BaseCoX
    
    
    
    for x in GroupList:
        Toggle=FindToggleState(EventNum)
        Draw.Toggle(x,EventNum,coX,coY,100,15,Toggle, "Delete: "+x,ToggleButton)
        coX+=ColWidth
        EventNum+=1
        if coX&gt;=BaseCoX+(ColWidth*VGColumns):
            coX=BaseCoX
            coY-=ColHeight    
    if coX!=BaseCoX:        
        coY-=ColHeight
    Draw.PushButton("Delete", 1, BaseCoX, coY, 100, 15,"Delete all selected Vertex Groups", DeleteVGroups)
        
    VGListRunning=0

def main():
    
    if GError: return        
    while VGListRunning == 1:
        Draw.UIBlock(buttons, 0)
        
    Window.EditMode(1)
    Window.EditMode(0)
    
    if InEditMode:
        Window.EditMode(1)

if __name__ == ' __main__':
    main()

```

(by the way if you want to change the number of columns that the vertex groups are displayed in, just change the item  
VGColumns=4 right near the top of the script to what ever number you want)

---

<div class="post-metadata">

**Author:** ![mikemayday](https://blenderartists.org/user_avatar/blenderartists.org/mikemayday/32/2687_2.png) [@mikemayday](https://blenderartists.org/u/mikemayday)\
**Post date:** [June 12, 2014, 4:50am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/2 "2014-06-12T04:50:50Z")

</div>

Hey there, is it possible to port this to 2.7?  
It’s a very useful script and I can’t find its counterpart for the latest versions.

EDIT: To be honest, I’m specifically looking for a script that will automatically remove all empty vertex groups from an object. Would anyone be willing to help, please?

---

<div class="post-metadata">

**Author:** ![CoDEmanX](https://blenderartists.org/letter_avatar_proxy/v4/letter/c/77aa72/32.png) [@CoDEmanX](https://blenderartists.org/u/CoDEmanX)\
**Post date:** [June 12, 2014, 4:43pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/3 "2014-06-12T16:43:19Z")

</div>

```auto
bl_info = {
    "name": "Remove unused Vertex Groups",
    "author": "CoDEmanX",
    "version": (1, 0),
    "blender": (2, 70, 0),
    "location": "Properties Editor &gt; Object data &gt; Vertex Groups &gt; Specials menu",
    "description": "Delete Vertex Groups with no assigned weight of active object",
    "warning": "",
    "wiki_url": "",
    "category": "Mesh"}

import bpy
from bpy.types import Operator

class OBJECT_OT_vertex_group_remove_unused(Operator):
    bl_idname = "object.vertex_group_remove_unused"
    bl_label = "Remove unused Vertex Groups"
    bl_options = {'REGISTER', 'UNDO'}

    @classmethod
    def poll(cls, context):
        return (context.object is not None and
                context.object.type == 'MESH')

    def execute(self, context):

        ob = context.object
        ob.update_from_editmode()
        
        vgroup_used = {i: False for i, k in enumerate(ob.vertex_groups)}
        
        for v in ob.data.vertices:
            for g in v.groups:
                if g.weight &gt; 0.0:
                    vgroup_used[g.group] = True
        
        for i, used in sorted(vgroup_used.items(), reverse=True):
            if not used:
                ob.vertex_groups.remove(ob.vertex_groups[i])
                
        return {'FINISHED'}

def draw_func(self, context):
    self.layout.operator(
        OBJECT_OT_vertex_group_remove_unused.bl_idname,
        icon='X'
    )

def register():
    bpy.utils.register_module( __name__ )
    bpy.types.MESH_MT_vertex_group_specials.prepend(draw_func)

def unregister():
    bpy.utils.unregister_module( __name__ )
    bpy.types.MESH_MT_vertex_group_specials.remove(draw_func)

if __name__ == " __main__":
    register()

```

It adds an entry to the VGroup specials menu

---

<div class="post-metadata">

**Author:** ![mikemayday](https://blenderartists.org/user_avatar/blenderartists.org/mikemayday/32/2687_2.png) [@mikemayday](https://blenderartists.org/u/mikemayday)\
**Post date:** [June 13, 2014, 12:38am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/4 "2014-06-13T00:38:33Z")

</div>

Worked like a charm, muchas gracias.

---

<div class="post-metadata">

**Author:** ![7quads](https://blenderartists.org/user_avatar/blenderartists.org/7quads/32/24526_2.png) [@7quads](https://blenderartists.org/u/7quads)\
**Post date:** [November 6, 2014, 1:15am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/5 "2014-11-06T01:15:03Z")

</div>

If you want to delete all vertex groups of an object, pythonically,  
for ob in bpy.data.objects[‘OBJECTNAME’].vertex\_groups:  
print(ob)  
bpy.data.objects[‘OBJECTNAME’].vertex\_groups.remove(ob)

---

<div class="post-metadata">

**Author:** ![jefftml](https://blenderartists.org/user_avatar/blenderartists.org/jefftml/32/902601_2.png) [@jefftml](https://blenderartists.org/u/jefftml)\
**Post date:** [November 21, 2014, 8:16am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/6 "2014-11-21T08:16:59Z")

</div>

7quads, don’t forget to indent!

```auto

for ob in bpy.data.objects['OBJECTNAME'].vertex_groups:
    print(ob)
    bpy.data.objects['OBJECTNAME'].vertex_groups.remove(ob)

```

---

<div class="post-metadata">

**Author:** ![CaptainAndrew](https://blenderartists.org/user_avatar/blenderartists.org/captainandrew/32/26729_2.png) [@CaptainAndrew](https://blenderartists.org/u/CaptainAndrew)\
**Post date:** [January 12, 2015, 3:36pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/7 "2015-01-12T15:36:53Z")

</div>

```auto

for ob in bpy.data.objects['OBJECTNAME'].vertex_groups:
    
    bpy.data.objects['OBJECTNAME'].vertex_groups.remove(ob)

```

How would you apply this to all selected objects? I am trying to remove all vertex groups on multiple objects and I really hope I don’t have to do them one at a time.

---

<div class="post-metadata">

**Author:** ![CoDEmanX](https://blenderartists.org/letter_avatar_proxy/v4/letter/c/77aa72/32.png) [@CoDEmanX](https://blenderartists.org/u/CoDEmanX)\
**Post date:** [January 13, 2015, 6:59am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/8 "2015-01-13T06:59:03Z")

</div>

It’s as simple as:

```auto
for ob in bpy.context.selected_editable_objects:
    for vgroup in ob.vertex_groups:
        ob.vertex_groups.remove(vgroup)

```

---

<div class="post-metadata">

**Author:** ![CaptainAndrew](https://blenderartists.org/user_avatar/blenderartists.org/captainandrew/32/26729_2.png) [@CaptainAndrew](https://blenderartists.org/u/CaptainAndrew)\
**Post date:** [January 13, 2015, 9:52am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/9 "2015-01-13T09:52:45Z")

</div>

Thank you CoDEmanX.

---

<div class="post-metadata">

**Author:** ![jerbot](https://blenderartists.org/user_avatar/blenderartists.org/jerbot/32/30803_2.png) [@jerbot](https://blenderartists.org/u/jerbot)\
**Post date:** [October 23, 2015, 2:14pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/10 "2015-10-23T14:14:04Z")

</div>

coDEmanX, this is awesome. Tested it in Blender 2.76 and it works like a charm. This is going to save me a LOT of tedious list scrolling.

Much luv, 3D brother.

---

<div class="post-metadata">

**Author:** ![Blackout330](https://blenderartists.org/letter_avatar_proxy/v4/letter/b/7993a0/32.png) [@Blackout330](https://blenderartists.org/u/Blackout330)\
**Post date:** [January 23, 2016, 8:53pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/11 "2016-01-23T20:53:44Z")

</div>

Sorry, I’m pretty damn new here, but how do you save and run scripts on Blender? I tried copy-pasting into console, don’t think it works…

---

<div class="post-metadata">

**Author:** ![BloodyRain2k](https://blenderartists.org/letter_avatar_proxy/v4/letter/b/34f0e0/32.png) [@BloodyRain2k](https://blenderartists.org/u/BloodyRain2k)\
**Post date:** [April 1, 2016, 3:51am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/12 "2016-04-01T03:51:12Z")

</div>

> [@CoDEmanX](#):
>
> It adds an entry to the VGroup specials menu

This works great in 2.77 but it also deletes empty mirror groups, like having only the L groups weighted for an armature and the R groups are just placeholders so the deformation get’s actually mirrored.  
I forgot that the empty mirror groups were neccessary and was wondering why my armature went weird suddenly and tracked it down to this having removed the empty R groups.

So could a check be added along “if groupname ends in .R or .L check the opposite for used == True” ?

I’d do it myself by I don’t know (nor like) python nor blender’s api yet, so maybe someone else who does know both can figure it out faster.

Edit: ok seems like I managed to fix this myself

```auto
bl_info = {
    "name": "Remove unused Vertex Groups",
    "author": "CoDEmanX",
    "version": (1, 0),
    "blender": (2, 70, 0),
    "location": "Properties Editor &gt; Object data &gt; Vertex Groups &gt; Specials menu",
    "description": "Delete Vertex Groups with no assigned weight of active object",
    "warning": "",
    "wiki_url": "",
    "category": "Mesh"
}

import bpy
from bpy.types import Operator

class OBJECT_OT_vertex_group_remove_unused(Operator):
    bl_idname = "object.vertex_group_remove_unused"
    bl_label = "Remove unused Vertex Groups"
    bl_options = {'REGISTER', 'UNDO'}

    @classmethod
    def poll(cls, context):
        return (context.object is not None and
                context.object.type == 'MESH')

    def execute(self, context):

        ob = context.object
        ob.update_from_editmode()
        
        vgs = ob.vertex_groups
        vgroup_used = {i: False for i, k in enumerate(ob.vertex_groups)}
        
        for v in ob.data.vertices:
            for g in v.groups:
                if g.weight &gt; 0.0:
                    vgroup_used[g.group] = True
                    g_name = vgs[g.group].name
                    if g_name.endswith(".L"):
                        vgroup_used[vgs.find(g_name[0:-1] + "R")] = True
                    if g_name.endswith(".R"):
                        vgroup_used[vgs.find(g_name[0:-1] + "L")] = True
        
        for i, used in sorted(vgroup_used.items(), reverse=True):
            if not used:
                ob.vertex_groups.remove(ob.vertex_groups[i])
                
        return {'FINISHED'}

def draw_func(self, context):
    self.layout.operator(
        OBJECT_OT_vertex_group_remove_unused.bl_idname,
        icon='X'
    )

def register():
    bpy.utils.register_module( __name__ )
    bpy.types.MESH_MT_vertex_group_specials.prepend(draw_func)

def unregister():
    bpy.utils.unregister_module( __name__ )
    bpy.types.MESH_MT_vertex_group_specials.remove(draw_func)

if __name__ == " __main__":
    register()

```

Probably fails for groups ending with non capital L/R but meh, works for me.

---

<div class="post-metadata">

**Author:** ![Pherim](https://blenderartists.org/user_avatar/blenderartists.org/pherim/32/557404_2.png) [@Pherim](https://blenderartists.org/u/Pherim)\
**Post date:** [August 4, 2018, 8:35am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/14 "2018-08-04T08:35:47Z")

</div>

Hello,

this doesn’t work for me, I get a syntax error (how can I copy script errors?).

It says “Syntax Error: Invalid Syntax” in line 38.

That would be this one:

`if g.weight &gt; 0.0:`

---

<div class="post-metadata">

**Author:** ![blablaalb](https://blenderartists.org/user_avatar/blenderartists.org/blablaalb/32/500078_2.png) [@blablaalb](https://blenderartists.org/u/blablaalb)\
**Post date:** [July 21, 2019, 12:01pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/15 "2019-07-21T12:01:58Z")

</div>

Awesome add-on. I had been using it everyday, till Blender 2.8 came out. Can you please upgrade it for Blender 2.8.

---

<div class="post-metadata">

**Author:** ![radeonoff](https://blenderartists.org/letter_avatar_proxy/v4/letter/r/977dab/32.png) [@radeonoff](https://blenderartists.org/u/radeonoff)\
**Post date:** [August 13, 2019, 5:06pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/16 "2019-08-13T17:06:36Z")

</div>

Updated to 2.8: [https://gumroad.com/l/Gxkbp](https://gumroad.com/l/Gxkbp)

---

<div class="post-metadata">

**Author:** ![radeonoff](https://blenderartists.org/letter_avatar_proxy/v4/letter/r/977dab/32.png) [@radeonoff](https://blenderartists.org/u/radeonoff)\
**Post date:** [April 17, 2020, 3:28pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/18 "2020-04-17T15:28:13Z")

</div>

what are u talking about? just type 0$ and u can download it for free. I’ve upload it on gumroad for convenience because it’s easy to share it that way.

---

<div class="post-metadata">

**Author:** ![raziel2001au](https://blenderartists.org/letter_avatar_proxy/v4/letter/r/5e9695/32.png) [@raziel2001au](https://blenderartists.org/u/raziel2001au)\
**Post date:** [April 17, 2020, 5:46pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/19 "2020-04-17T17:46:04Z")

</div>

Ah, I stand corrected, didn’t realise you could actually enter 0. Sorry. In that case I’ll kill my message, since it’s probably quite useless now :).

---

<div class="post-metadata">

**Author:** ![frdismx](https://blenderartists.org/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@frdismx](https://blenderartists.org/u/frdismx)\
**Post date:** [July 23, 2020, 11:42pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/20 "2020-07-23T23:42:03Z")

</div>

Hey, radenoff! Just to let you know that the gumroad download seems to be corrupted. The rar file doesnt include the 2.8 folder and throws an error when attempting to extract. Any chance you can upload again?

Also, as a suggestion, wouldn’t the script be even easier to share if it was a github repo? That way people would get access to previous versions, and could even contribute with their fixes, in a more structured way than a forum thread. Just a suggestion.

---

<div class="post-metadata">

**Author:** ![COnLOAR](https://blenderartists.org/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@COnLOAR](https://blenderartists.org/u/COnLOAR)\
**Post date:** [August 17, 2020, 8:18am UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/21 "2020-08-17T08:18:11Z")

</div>

Gumroad forces you to enter an email address, and if you feel like being honest, it doesn’t tell you that they’re giving out your actual email address to the uploader (I just use random words like [NotTellingYou@somesite.com](mailto:NotTellingYou@somesite.com)).  
The only convenience I see is offering people a more intertwined “option” to donate money _(since BA allow file uploads)_.

But that aside, I came here to say I tweaked CodemanX’s code a while ago but neglected to add that in my notes, and then thought I made it 🤣

* * *

If anyone wants to use CoDEmanX’s code or BloodyRain2k’s, you have to replace [`&gt;`] with [`>`].  
I believe that’s a glitch from the new forum’s system migration.

* * *

Here is the version that I tweaked:  
[remove\_unused\_vertex\_groups.py](https://blenderartists.org/uploads/short-url/3z3lZbfi6RFPOK0JtKxL0nR44CZ.py) (2.9 KB)

The functional difference from CoDEmanX’s is you can run it on multiple objects _(alt+click)_, and it keeps vertex groups used by shape keys and modifiers. Not constraints, as those can be set from bones and other objects and I don’t even use them, so I just didn’t bother ¯\_(ツ)\_/¯.

---

<div class="post-metadata">

**Author:** ![zumoblender](https://blenderartists.org/letter_avatar_proxy/v4/letter/z/49beb7/32.png) [@zumoblender](https://blenderartists.org/u/zumoblender)\
**Post date:** [August 19, 2020, 8:15pm UTC](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881/22 "2020-08-19T20:15:46Z")

</div>

> [@COnLOAR](#):
>
> The only convenience I see is offering people a more intertwined “option” to donate money _(since BA allow file uploads)_ .

Actually there is another convenience. You will get updates email for the downloaded add-on if you use an accesible email address.

[Next page](https://blenderartists.org/t/batch-delete-vertex-groups-script/449881.md?page=2)
