做的東西多了 測試的東西多了 難免會多出一堆空的頂點組 還沒有一鍵刪除的方法 而且頂點組也不能多選 一個一個刪除麻煩死了 在se找到了解決方案
import bpy
def survey(obj):
maxWeight = {}
for i in obj.vertex_groups:
maxWeight[i.index] = 0
for v in obj.data.vertices:
for g in v.groups:
gn = g.group
w = obj.vertex_groups[g.group].weight(v.index)
if (maxWeight.get(gn) is None or w>maxWeight[gn]):
maxWeight[gn] = w
return maxWeight
obj = bpy.context.active_object
maxWeight = survey(obj)
# fix bug pointed out by user2859
ka = []
ka.extend(maxWeight.keys())
ka.sort(key=lambda gn: -gn)
print (ka)
for gn in ka:
if maxWeight[gn]<=0:
print ("delete %d"%gn)
obj.vertex_groups.remove(obj.vertex_groups[gn]) # actually remove the group
如果是多個物體呢 稍微改一下就是了 使用bpy.context.selected_objects