Move 'render auto tile size' addon to main repo.
[blender-addons-contrib.git] / mesh_select_vertex_groups.py
index c9922cbca0a9d91950eac9f2ccd8e8733fcb2cdc..7d9fb6f52b60f9585e89f3c3e260cc605870b2ea 100644 (file)
 # ##### END GPL LICENSE BLOCK #####
 
 bl_info = {
-    'name': 'Select Vertex Groups',
-    'author': 'Martin Ellison',
-    'version': (1, 0),
-    'blender': (2, 5, 9),
-    'api': 39105,
-    'location': 'Toolbox',
-    'description': 'Finds all the vertex groups that chosen verts are in, & any verts that are not in any group',
-    'warning': '', # used for warning icon and text in addons panel
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
-        "Scripts/Modeling/Select_Vertex_Groups",
-    'tracker_url': 'https://projects.blender.org/tracker/index.php?'\
-        'func=detail&aid=22025',
-    'category': 'Mesh'}
+    "name": "Select Vertex Groups",
+    "author": "Martin Ellison",
+    "version": (1, 0),
+    "blender": (2, 71, 0),
+    "location": "Toolbox",
+    "description": "Finds all the vertex groups that chosen verts are in, & any verts that are not in any group",
+    "warning": "Buggy", # used for warning icon and text in addons panel
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+                "Scripts/Modeling/Select_Vertex_Groups",
+    "tracker_url": "https://developer.blender.org/T22025",
+    "category": "Mesh"}
 
 """
 This script finds all the vertex groups that chosen vertexes are in, and any vertexes that are not in any vertex group.
@@ -120,86 +118,87 @@ class DeselectFound(bpy.types.Operator):
         return {'FINISHED'}
 
 def set_used():
-        global use_selected_only, used_vertexes, the_mesh, vertex_usage
-        obj = bpy.context.active_object
-        used_vertexes = set()
-        if use_selected_only:
-                for v in obj.data.vertices:
-                        if v.select: used_vertexes.add(v.index)
-        else:
-                for v in obj.data.vertices: used_vertexes.add(v.index)
-        the_mesh = obj
-        vertex_usage = '%d vertexes used' % (len(used_vertexes))
+    global use_selected_only, used_vertexes, the_mesh, vertex_usage
+    obj = bpy.context.active_object
+    used_vertexes = set()
+    if use_selected_only:
+        for v in obj.data.vertices:
+            if v.select: used_vertexes.add(v.index)
+    else:
+        for v in obj.data.vertices: used_vertexes.add(v.index)
+    the_mesh = obj
+    vertex_usage = '%d vertexes used' % (len(used_vertexes))
 
 
 def make_groups(limit):
-        global used_vertexes
-        vgp = []
-        vgdict = {}
-        vgused = {}
-        obj = bpy.context.active_object
-        all_in_group = True
-        for vg in obj.vertex_groups:
-                vgdict[vg.index] = vg.name
-        for v in obj.data.vertices:
-                in_group = False
-                if v.index in used_vertexes:
-                        for g in v.groups:
-                                gr = g.group
-                                w = g.weight
-                                if w > limit:
-                                        if not gr in vgused: vgused[gr] = 0
-                                        vgused[gr] += 1
-                                        in_group = True
-                if not in_group: all_in_group = False
-        if not all_in_group:
-                vgp.append(("no group", "(No group)"))
-        for gn in vgused.keys():
-                name = vgdict[gn]
-                vgp.append((name, '%s has %d vertexes' % (name, vgused[gn]) ))
-        print("%d groups found\n" % len(vgp))
-        return vgp
+    global used_vertexes
+    vgp = []
+    vgdict = {}
+    vgused = {}
+    obj = bpy.context.active_object
+    all_in_group = True
+    for vg in obj.vertex_groups:
+        vgdict[vg.index] = vg.name
+    for v in obj.data.vertices:
+        in_group = False
+        if v.index in used_vertexes:
+            for g in v.groups:
+                gr = g.group
+                w = g.weight
+                if w > limit:
+                    if not gr in vgused: vgused[gr] = 0
+                    vgused[gr] += 1
+                    in_group = True
+        if not in_group: all_in_group = False
+    if not all_in_group:
+        vgp.append(("no group", "(No group)"))
+    for gn in vgused.keys():
+        name = vgdict[gn]
+        vgp.append((name, '%s has %d vertexes' % (name, vgused[gn]) ))
+    print("%d groups found\n" % len(vgp))
+    return vgp
 
 def found_verts(vertex_group):
-        global used_vertexes
-        vgfound = []
-        obj = bpy.context.active_object
-        if vertex_group == 'no group':
-                for v in obj.data.vertices:
-                        if v.index in used_vertexes and len(v.groups) == 0:
-                                vgfound.append(v)
-        else:
-                vgnum = -1
-                for vg in obj.vertex_groups:
-                        if vg.name == vertex_group: vgnum = vg.index
-                for v in obj.data.vertices:
-                        if v.index in used_vertexes:
-                                found = False
-                                for g in v.groups:
-                                        if g.group == vgnum: found = True
-                                if found: vgfound.append(v)
-        print('%d vertexes found for %s' % (len(vgfound), vertex_group))
-        return vgfound
+    global used_vertexes
+    vgfound = []
+    obj = bpy.context.active_object
+    if vertex_group == 'no group':
+        for v in obj.data.vertices:
+            if v.index in used_vertexes and (not v.groups):
+                vgfound.append(v)
+    else:
+        vgnum = obj.vertex_groups.find(vertex_group)
+        for v in obj.data.vertices:
+            if v.index in used_vertexes:
+                for g in v.groups:
+                    if g.group == vgnum:
+                        vgfound.append(v)
+                        break
+
+    print('%d vertexes found for %s' % (len(vgfound), vertex_group))
+    return vgfound
 
 
 class VIEW3D_PT_FixVertexGroups(bpy.types.Panel):
     bl_space_type = "VIEW_3D"
     bl_region_type = "TOOLS"
     bl_label = "Select Vertex Groups"
+    bl_category = 'Tools'
+    bl_options = {'DEFAULT_CLOSED'}
 
     @classmethod
     def poll(self, context):
         if bpy.context.active_object:
-           obj = bpy.context.active_object
-           if obj.type == 'MESH' and obj.mode == 'EDIT': return True
+            obj = bpy.context.active_object
+            if obj.type == 'MESH' and obj.mode == 'EDIT': return True
         return False
 
     def draw(self, context):
         global use_selected_only, used_vertexes, the_mesh, vertex_usage
 
         if bpy.context.active_object:
-           obj = bpy.context.active_object
-           if obj.type == 'MESH' and obj.mode == 'EDIT':
+            obj = bpy.context.active_object
+            if obj.type == 'MESH' and obj.mode == 'EDIT':
                 layout = self.layout
                 use_all = layout.operator("mesh.primitive_fvg_useall", "Use all vertexes")
                 layout.operator("mesh.primitive_fvg_useselected", "Use selected vertexes")
@@ -213,12 +212,12 @@ class VIEW3D_PT_FixVertexGroups(bpy.types.Panel):
                 #groups = make_groups(use_all.limitval)
                 groups = make_groups(0.01)
                 for gp in groups:
-                        layout.label(text = gp[1])
-                        row = layout.row()
-                        sel_op = row.operator("mesh.primitive_fvg_selfound", "Select")
-                        sel_op.vertexgroup = gp[0]
-                        desel_op = row.operator("mesh.primitive_fvg_deselfound", "Deselect")
-                        desel_op.vertexgroup = gp[0]
+                    layout.label(text = gp[1])
+                    row = layout.row()
+                    sel_op = row.operator("mesh.primitive_fvg_selfound", "Select")
+                    sel_op.vertexgroup = gp[0]
+                    desel_op = row.operator("mesh.primitive_fvg_deselfound", "Deselect")
+                    desel_op.vertexgroup = gp[0]
 
 classes = [UseAll, UseSelected, SelectFound, DeselectFound]