2
"name": "Select by index",
6
"location": "View3D > Tool Shelf",
7
"description": "Select mesh data by index / area / length / cursor",
11
from mathutils import Vector
13
class SelVert(bpy.types.Operator):
14
bl_idname = 'mesh.select_vert_index'
16
bl_description = 'Select vertices by index'
17
bl_options = {'REGISTER', 'UNDO'}
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')
24
def poll(cls, context):
25
return (context.object and context.object.type == 'MESH')
27
def draw(self, context):
29
layout.prop(self,'indice', slider=True)
30
layout.prop(self,'delta')
31
layout.prop(self,'flip')
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
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)
48
for i in range(len(sel[:valor])):
49
ver[sel[i][1]].select = True
51
for i in range(len(sel[:valor])):
53
ver[len(sel)-i-1].select = True
56
bpy.ops.object.mode_set(mode='EDIT')
59
class SelEdge(bpy.types.Operator):
60
bl_idname = 'mesh.select_edge_index'
62
bl_description = 'Select edges by index'
63
bl_options = {'REGISTER', 'UNDO'}
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')
70
def poll(cls, context):
71
return (context.object and context.object.type == 'MESH')
73
def draw(self, context):
75
layout.prop(self,'indice', slider=True)
76
layout.prop(self,'delta')
77
layout.prop(self,'flip')
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
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)
94
for i in range(len(sel[:valor])):
95
edg[sel[i][1]].select = True
97
for i in range(len(sel[:valor])):
99
edg[len(sel)-i-1].select = True
102
bpy.ops.object.mode_set(mode='EDIT')
105
class SelFace(bpy.types.Operator):
106
bl_idname = 'mesh.select_face_index'
108
bl_description = 'Select faces by index'
109
bl_options = {'REGISTER', 'UNDO'}
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')
116
def poll(cls, context):
117
return (context.object and context.object.type == 'MESH')
119
def draw(self, context):
121
layout.prop(self,'indice', slider=True)
122
layout.prop(self,'delta')
123
layout.prop(self,'flip')
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
133
sel.append((f.area, f.index))
134
sel.sort(reverse=self.flip)
136
bpy.ops.object.mode_set()
137
valor = round(len(sel) / 100 * self.indice)
139
for i in range(len(sel[:valor])):
140
fac[sel[i][1]].select = True
142
for i in range(len(sel[:valor])):
144
fac[len(sel)-i-1].select = True
147
bpy.ops.object.mode_set(mode='EDIT')
150
class GUI(bpy.types.Panel):
151
bl_label = 'Select mesh data'
152
bl_space_type = 'VIEW_3D'
153
bl_region_type = 'TOOLS'
155
def draw(self, context):
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')
163
bpy.utils.register_class(SelVert)
164
bpy.utils.register_class(SelEdge)
165
bpy.utils.register_class(SelFace)
166
bpy.utils.register_class(GUI)
169
bpy.utils.unregister_class(SelVert)
170
bpy.utils.unregister_class(SelEdge)
171
bpy.utils.unregister_class(SelFace)
172
bpy.utils.unregister_class(GUI)
174
if __name__ == '__main__':