~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons_contrib/mesh_select_tools/mesh_index_select.py

  • Committer: Reinhard Tartler
  • Date: 2014-05-31 01:50:05 UTC
  • mfrom: (14.2.27 sid)
  • Revision ID: siretart@tauware.de-20140531015005-ml6druahuj82nsav
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
bl_info = {
 
2
    "name": "Select by index",
 
3
    "author": "liero",
 
4
    "version": (0, 2),
 
5
    "blender": (2, 55, 0),
 
6
    "location": "View3D > Tool Shelf",
 
7
    "description": "Select mesh data by index / area / length / cursor",
 
8
    "category": "Mesh"}
 
9
 
 
10
import bpy, mathutils
 
11
from mathutils import Vector
 
12
 
 
13
class SelVert(bpy.types.Operator):
 
14
    bl_idname = 'mesh.select_vert_index'
 
15
    bl_label = 'Verts'
 
16
    bl_description = 'Select vertices by index'
 
17
    bl_options = {'REGISTER', 'UNDO'}
 
18
 
 
19
    indice = bpy.props.FloatProperty(name='Selected', default=0, min=0, max=100, description='Percentage of selected edges', precision = 2, subtype = 'PERCENTAGE')
 
20
    delta = bpy.props.BoolProperty(name='Use Cursor', default=False, description='Select by Index / Distance to Cursor')
 
21
    flip = bpy.props.BoolProperty(name='Reverse Order', default=False, description='Reverse selecting order')
 
22
 
 
23
    @classmethod
 
24
    def poll(cls, context):
 
25
        return (context.object and context.object.type == 'MESH')
 
26
 
 
27
    def draw(self, context):
 
28
        layout = self.layout
 
29
        layout.prop(self,'indice', slider=True)
 
30
        layout.prop(self,'delta')
 
31
        layout.prop(self,'flip')
 
32
 
 
33
    def execute(self, context):
 
34
        obj = bpy.context.object
 
35
        mode = [a for a in bpy.context.tool_settings.mesh_select_mode]
 
36
        if mode != [True, False, False]:
 
37
            bpy.context.tool_settings.mesh_select_mode = [True, False, False]
 
38
        ver = obj.data.vertices
 
39
        loc = context.scene.cursor_location
 
40
        sel = []
 
41
        for v in ver:
 
42
            d = v.co - loc
 
43
            sel.append((d.length, v.index))
 
44
        sel.sort(reverse=self.flip)
 
45
        bpy.ops.object.mode_set()
 
46
        valor = round(len(sel) / 100 * self.indice)
 
47
        if self.delta:
 
48
            for i in range(len(sel[:valor])):
 
49
                ver[sel[i][1]].select = True
 
50
        else:
 
51
            for i in range(len(sel[:valor])):
 
52
                if self.flip:
 
53
                    ver[len(sel)-i-1].select = True
 
54
                else:
 
55
                    ver[i].select = True
 
56
        bpy.ops.object.mode_set(mode='EDIT')
 
57
        return {'FINISHED'}
 
58
 
 
59
class SelEdge(bpy.types.Operator):
 
60
    bl_idname = 'mesh.select_edge_index'
 
61
    bl_label = 'Edges'
 
62
    bl_description = 'Select edges by index'
 
63
    bl_options = {'REGISTER', 'UNDO'}
 
64
 
 
65
    indice = bpy.props.FloatProperty(name='Selected', default=0, min=0, max=100, description='Percentage of selected edges', precision = 2, subtype = 'PERCENTAGE')
 
66
    delta = bpy.props.BoolProperty(name='Use Edges Length', default=False, description='Select Edges by Index / Length')
 
67
    flip = bpy.props.BoolProperty(name='Reverse Order', default=False, description='Reverse selecting order')
 
68
 
 
69
    @classmethod
 
70
    def poll(cls, context):
 
71
        return (context.object and context.object.type == 'MESH')
 
72
 
 
73
    def draw(self, context):
 
74
        layout = self.layout
 
75
        layout.prop(self,'indice', slider=True)
 
76
        layout.prop(self,'delta')
 
77
        layout.prop(self,'flip')
 
78
 
 
79
    def execute(self, context):
 
80
        obj = bpy.context.object
 
81
        mode = [a for a in bpy.context.tool_settings.mesh_select_mode]
 
82
        if mode != [False, True, False]:
 
83
            bpy.context.tool_settings.mesh_select_mode = [False, True, False]
 
84
        ver = obj.data.vertices
 
85
        edg = obj.data.edges
 
86
        sel = []
 
87
        for e in edg:
 
88
            d = ver[e.vertices[0]].co - ver[e.vertices[1]].co
 
89
            sel.append((d.length, e.index))
 
90
        sel.sort(reverse=self.flip)
 
91
        bpy.ops.object.mode_set()
 
92
        valor = round(len(sel) / 100 * self.indice)
 
93
        if self.delta:
 
94
            for i in range(len(sel[:valor])):
 
95
                edg[sel[i][1]].select = True
 
96
        else:
 
97
            for i in range(len(sel[:valor])):
 
98
                if self.flip:
 
99
                    edg[len(sel)-i-1].select = True
 
100
                else:
 
101
                    edg[i].select = True
 
102
        bpy.ops.object.mode_set(mode='EDIT')
 
103
        return {'FINISHED'}
 
104
 
 
105
class SelFace(bpy.types.Operator):
 
106
    bl_idname = 'mesh.select_face_index'
 
107
    bl_label = 'Faces'
 
108
    bl_description = 'Select faces by index'
 
109
    bl_options = {'REGISTER', 'UNDO'}
 
110
 
 
111
    indice = bpy.props.FloatProperty(name='Selected', default=0, min=0, max=100, description='Percentage of selected faces', precision = 2, subtype = 'PERCENTAGE')
 
112
    delta = bpy.props.BoolProperty(name='Use Faces Area', default=False, description='Select Faces by Index / Area')
 
113
    flip = bpy.props.BoolProperty(name='Reverse Order', default=False, description='Reverse selecting order')
 
114
 
 
115
    @classmethod
 
116
    def poll(cls, context):
 
117
        return (context.object and context.object.type == 'MESH')
 
118
 
 
119
    def draw(self, context):
 
120
        layout = self.layout
 
121
        layout.prop(self,'indice', slider=True)
 
122
        layout.prop(self,'delta')
 
123
        layout.prop(self,'flip')
 
124
 
 
125
    def execute(self, context):
 
126
        obj = bpy.context.object
 
127
        mode = [a for a in bpy.context.tool_settings.mesh_select_mode]
 
128
        if mode != [False, False, True]:
 
129
            bpy.context.tool_settings.mesh_select_mode = [False, False, True]
 
130
        fac = obj.data.polygons
 
131
        sel = []
 
132
        for f in fac:
 
133
            sel.append((f.area, f.index))
 
134
        sel.sort(reverse=self.flip)
 
135
        print (sel)
 
136
        bpy.ops.object.mode_set()
 
137
        valor = round(len(sel) / 100 * self.indice)
 
138
        if self.delta:
 
139
            for i in range(len(sel[:valor])):
 
140
                fac[sel[i][1]].select = True
 
141
        else:
 
142
            for i in range(len(sel[:valor])):
 
143
                if self.flip:
 
144
                    fac[len(sel)-i-1].select = True
 
145
                else:
 
146
                    fac[i].select = True
 
147
        bpy.ops.object.mode_set(mode='EDIT')
 
148
        return {'FINISHED'}
 
149
 
 
150
class GUI(bpy.types.Panel):
 
151
    bl_label = 'Select mesh data'
 
152
    bl_space_type = 'VIEW_3D'
 
153
    bl_region_type = 'TOOLS'
 
154
 
 
155
    def draw(self, context):
 
156
        layout = self.layout
 
157
        row = layout.row(align=True)
 
158
        row.operator('mesh.select_vert_index')
 
159
        row.operator('mesh.select_edge_index')
 
160
        row.operator('mesh.select_face_index')
 
161
 
 
162
def register():
 
163
    bpy.utils.register_class(SelVert)
 
164
    bpy.utils.register_class(SelEdge)
 
165
    bpy.utils.register_class(SelFace)
 
166
    bpy.utils.register_class(GUI)
 
167
 
 
168
def unregister():
 
169
    bpy.utils.unregister_class(SelVert)
 
170
    bpy.utils.unregister_class(SelEdge)
 
171
    bpy.utils.unregister_class(SelFace)
 
172
    bpy.utils.unregister_class(GUI)
 
173
 
 
174
if __name__ == '__main__':
 
175
    register()
 
176