1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENCE BLOCK #####
bl_info = {
"name": "Select Tools",
"author": "Jakub Belcik",
"version": (1, 0, 2),
"blender": (2, 7, 3),
"location": "3D View > Tools",
"description": "Selection Tools",
"warning": "",
"wiki_url": "",
"category": ""
}
import bpy
from bpy.types import Operator
from bpy.props import (
BoolProperty,
EnumProperty,
)
class ShowHideObject(Operator):
bl_idname = "opr.show_hide_object"
bl_label = "Show/Hide Object"
bl_description = ("Flip the viewport visibility for all objects in the Data\n"
"(Hidden to Visible and Visible to Hidden)")
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
if context.object is None:
self.report({'INFO'},
"Show/Hide: No Object found. Operation Cancelled")
return {'CANCELLED'}
if context.object.mode != 'OBJECT':
self.report({'INFO'},
"Show/Hide: This operation can be performed only in object mode")
return {'CANCELLED'}
for i in bpy.data.objects:
try:
if i.hide:
i.hide = False
i.hide_select = False
i.hide_render = False
else:
i.hide = True
i.select = False
if i.type not in ['CAMERA', 'LAMP']:
i.hide_render = True
except:
continue
return {'FINISHED'}
class ShowAllObjects(Operator):
bl_idname = "opr.show_all_objects"
bl_label = "Show All Objects"
bl_description = "Show all objects"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
for i in bpy.data.objects:
try:
i.hide = False
i.hide_select = False
i.hide_render = False
except:
continue
return {'FINISHED'}
class HideAllObjects(Operator):
bl_idname = "opr.hide_all_objects"
bl_label = "Hide All Inactive"
bl_description = "Hide all inactive objects"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
if context.object is None:
for i in bpy.data.objects:
i.hide = True
i.select = False
if i.type not in ['CAMERA', 'LAMP']:
i.hide_render = True
else:
obj_name = context.object.name
for i in bpy.data.objects:
if i.name != obj_name:
i.hide = True
i.select = False
if i.type not in ['CAMERA', 'LAMP']:
i.hide_render = True
return {'FINISHED'}
class SelectAll(Operator):
bl_idname = "opr.select_all"
bl_label = "(De)select All"
bl_description = "(De)select all objects, verticies, edges or faces"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
if context.object is None:
bpy.ops.object.select_all(action='TOGGLE')
elif context.object.mode == 'EDIT':
bpy.ops.mesh.select_all(action='TOGGLE')
elif context.object.mode == 'OBJECT':
bpy.ops.object.select_all(action='TOGGLE')
else:
self.report({'ERROR'},
"(De)select All: Cannot perform this operation in this mode")
return {'CANCELLED'}
return {'FINISHED'}
class InverseSelection(Operator):
bl_idname = "opr.inverse_selection"
bl_label = "Inverse Selection"
bl_description = "Inverse selection"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
if context.object is None:
bpy.ops.object.select_all(action='INVERT')
elif context.object.mode == 'EDIT':
bpy.ops.mesh.select_all(action='INVERT')
elif context.object.mode == 'OBJECT':
bpy.ops.object.select_all(action='INVERT')
else:
self.report({'ERROR'},
"Inverse Selection: Cannot perform this operation in this mode")
return {'CANCELLED'}
return {'FINISHED'}
class LoopMultiSelect(Operator):
bl_idname = "opr.loop_multi_select"
bl_label = "Edge Loop Select"
bl_description = "Select a loop of connected edges"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
if context.object.mode != 'EDIT':
self.report({'ERROR'}, "This operation can be performed only in edit mode")
return {'CANCELLED'}
try:
bpy.ops.mesh.loop_multi_select(ring=False)
except:
self.report({'WARNING'},
"Edge loop select: Operation could not be performed (See Console for more info)")
return {'CANCELLED'}
return {'FINISHED'}
class ShowRenderAllSelected(Operator):
bl_idname = "op.render_show_all_selected"
bl_label = "Render On"
bl_description = "Render all objects"
def execute(self, context):
for ob in bpy.data.objects:
try:
if ob.select is True:
ob.hide_render = False
except:
continue
return {'FINISHED'}
class HideRenderAllSelected(Operator):
bl_idname = "op.render_hide_all_selected"
bl_label = "Render Off"
bl_description = "Hide Selected Object(s) from Render"
def execute(self, context):
for ob in bpy.data.objects:
try:
if ob.select is True:
ob.hide_render = True
except:
continue
return {'FINISHED'}
class OBJECT_OT_HideShowByTypeTemplate():
bl_options = {'UNDO', 'REGISTER'}
type = EnumProperty(
items=(
('MESH', 'Mesh', ''),
('CURVE', 'Curve', ''),
('SURFACE', 'Surface', ''),
('META', 'Meta', ''),
('FONT', 'Font', ''),
('ARMATURE', 'Armature', ''),
('LATTICE', 'Lattice', ''),
('EMPTY', 'Empty', ''),
('CAMERA', 'Camera', ''),
('LAMP', 'Lamp', ''),
('ALL', 'All', '')),
name="Type",
description="Type",
default='LAMP',
options={'ANIMATABLE'}
)
def execute(self, context):
scene = bpy.context.scene
objects = []
eligible_objects = []
# Only Selected?
if self.hide_selected:
objects = bpy.context.selected_objects
else:
objects = scene.objects
# Only Specific Types? + Filter layers
for obj in objects:
for i in range(0, 20):
if obj.layers[i] & scene.layers[i]:
if self.type == 'ALL' or obj.type == self.type:
if obj not in eligible_objects:
eligible_objects.append(obj)
objects = eligible_objects
eligible_objects = []
# Only Render Restricted?
if self.hide_render_restricted:
for obj in objects:
if obj.hide_render == self.hide_or_show:
eligible_objects.append(obj)
objects = eligible_objects
eligible_objects = []
# Perform Hiding / Showing
for obj in objects:
obj.hide = self.hide_or_show
return {'FINISHED'}
def invoke(self, context, event):
return self.execute(context)
# show hide by type # by Felix Schlitter
class OBJECT_OT_HideByType(OBJECT_OT_HideShowByTypeTemplate, Operator):
bl_idname = "object.hide_by_type"
bl_label = "Hide By Type"
hide_or_show = BoolProperty(
name="Hide",
description="Inverse effect",
options={'HIDDEN'},
default=1
)
hide_selected = BoolProperty(
name="Selected",
description="Hide only selected objects",
default=0
)
hide_render_restricted = BoolProperty(
name="Only Render-Restricted",
description="Hide only render restricted objects",
default=0
)
class OBJECT_OT_ShowByType(OBJECT_OT_HideShowByTypeTemplate, Operator):
bl_idname = "object.show_by_type"
bl_label = "Show By Type"
hide_or_show = BoolProperty(
name="Hide",
description="Inverse effect",
options={'HIDDEN'},
default=0
)
hide_selected = BoolProperty(
name="Selected",
options={'HIDDEN'},
default=0
)
hide_render_restricted = BoolProperty(
name="Only Renderable",
description="Show only non render restricted objects",
default=0
)
# Register
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == '__main__':
register()
|