3
Name: 'Invert Active Group'
6
Tooltip: 'Invert the active vertex group'
9
# --------------------------------------------------------------------------
10
# ***** BEGIN GPL LICENSE BLOCK *****
12
# This program is free software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software Foundation,
24
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
# ***** END GPL LICENCE BLOCK *****
27
# --------------------------------------------------------------------------
29
from Blender import Scene, Mesh, Window, sys
34
def vgroup_invert(ob_orig, me):
35
if not me.getVertGroupNames():
37
group_act = me.activeGroup
41
group_data = me.getVertsFromGroup(group_act, 1)
43
weights= [1.0] * len(me.verts) # 1.0 - initialize inverted
45
group_data = me.getVertsFromGroup(group_act, 1) # (i,w) tuples.
47
me.removeVertGroup(group_act) # messes up the active group.
48
for i,w in group_data:
51
me.addVertGroup(group_act)
53
rep = Blender.Mesh.AssignModes.REPLACE
55
for i,weight in enumerate(weights):
57
me.assignVertsToGroup(group_act, vertList, weight, rep)
59
me.activeGroup = group_act
64
# Gets the current scene, there can be many scenes in 1 blend file.
65
sce = bpy.data.scenes.active
67
# Get the active object, there can only ever be 1
68
# and the active object is always the editmode object.
69
ob_act = sce.objects.active
71
if not ob_act or ob_act.type != 'Mesh':
72
BPyMessages.Error_NoMeshActive()
75
# Saves the editmode state and go's out of
76
# editmode if its enabled, we cant make
77
# changes to the mesh data while in editmode.
78
is_editmode = Window.EditMode()
82
me = ob_act.getData(mesh=1) # old NMesh api is default
85
# Run the mesh editing function
86
vgroup_invert(ob_act, me)
88
# Timing the script is a good way to be aware on any speed hits when scripting
89
print 'Invert VGroup in %.2f seconds' % (sys.time()-t)
91
if is_editmode: Window.EditMode(1)
93
# This lets you can import the script without running it
94
if __name__ == '__main__':
b'\\ No newline at end of file'