-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmiscOt.py
708 lines (512 loc) · 20.9 KB
/
miscOt.py
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
import bpy
from . properties import ntzsf_scene_props
from . import miscFunc
from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty)
from bpy.types import (Panel, Operator, AddonPreferences, PropertyGroup)
# -----------------------------------------------------------------------------
# Add Object to Excluded Isolate Objects
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_add_obj_to_excluded_isolate_objs(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_add_obj_to_excluded_isolate_objs"
bl_label = 'NTZSF : Add obj to "Isolate Exclusion List"'
bl_description = 'Add the object to the list of excluded isolated objects'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scene = context.scene
selObjs = [obj for obj in bpy.context.selected_objects]
for obj in selObjs:
scene.ntzSmFrm.excludedIsolateObjects.add(obj.name)
obj['ntzSmFrm_isolateExcluded'] = 1
#Object added to the "excludedIsolateObjects" list
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Remove Object From Excluded Isolate Objects
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_del_obj_from_excluded_isolate_objs(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_del_obj_from_excluded_isolate_objs"
bl_label = 'NTZSF : Remove obj from "Isolate Exclusion List"'
bl_description = 'Remove the object from the excluded isolated objects'
bl_options = {'REGISTER', 'UNDO'}
objectToUntemplate : StringProperty(
name="Object to Remove",
description="Name of the Object to remove (Default = None)",
default = "None"
)
@classmethod
def poll(cls, context):
return True
def draw(self, context):
pass
#END draw()
def execute(self, context):
scene = context.scene
if self.objectToUntemplate == "None":
#User clicked the "-" button. Remove multiple objects that are selected
selObjs = [obj for obj in bpy.context.selected_objects]
for obj in selObjs:
#if object name is in the scene list of excluded isolate objects, then remove it.
if obj.name in scene.ntzSmFrm.excludedIsolateObjects:
scene.ntzSmFrm.excludedIsolateObjects.remove(obj.name)
#check to see if the prop "Neltulz_Isolate_Exlcluded" is on the selected object, if so, remove it.
try:
obj.pop('ntzSmFrm_isolateExcluded')
except:
pass
else:
#User clicked the "X" next to an object in the list of excluded objects from isolate. Remove the single object.
obj = None
try:
obj = bpy.data.objects[self.objectToUntemplate]
except:
pass
if obj is not None:
#if object name is in the scene list of excluded isolate objects, then remove it.
if obj.name in scene.ntzSmFrm.excludedIsolateObjects:
scene.ntzSmFrm.excludedIsolateObjects.remove(obj.name)
#check to see if the prop "Neltulz_Isolate_Exlcluded" is on the selected object, if so, remove it.
try:
obj.pop('ntzSmFrm_isolateExcluded')
except:
pass
#removed custom property from object
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Refresh Excluded Isolate Objects
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_refresh_excluded_isolate_objs(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_refresh_excluded_isolate_objs"
bl_label = 'NTZSF : Refresh "Isolate Exclusion List"'
bl_description = 'Refresh the list of excluded isolated objects. Useful if you have renamed objects and the list no longer matches'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scene = context.scene
objs = [obj for obj in bpy.context.scene.objects]
scene.ntzSmFrm.excludedIsolateObjects.clear()
for obj in objs:
try:
if obj['ntzSmFrm_isolateExcluded']:
scene.ntzSmFrm.excludedIsolateObjects.add(obj.name)
except:
pass
#Refreshed
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Clear all Excluded Isolate Objects
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_clear_all_excluded_isolate_objs(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_clear_all_excluded_isolate_objs"
bl_label = 'NTZSF : Clear "Isolate Exclusion List"'
bl_description = 'Clear the list of excluded isolated objects.'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scene = context.scene
objs = [obj for obj in bpy.context.scene.objects]
scene.ntzSmFrm.excludedIsolateObjects.clear()
for obj in objs:
try:
obj.pop('ntzSmFrm_isolateExcluded')
except:
pass
#Cleared
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Template (Converts object to wireframe with click-through)
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_convert_obj_to_template(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_convert_obj_to_template"
bl_label = 'NTZSF : Add obj to "Templated Obj List"'
bl_description = 'Converts object to wireframe with click-through'
bl_options = {'REGISTER', 'UNDO'}
makeSelectable : BoolProperty (
name="Make Template Selectable",
description="Make the template object selectable (Default = False)",
default = False
)
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scene = context.scene
activeObj = bpy.context.view_layer.objects.active
modeAtBegin = "Unknown" #declare
try:
#try to determine objectMode
modeAtBegin = bpy.context.object.mode
except:
modeAtBegin = "OBJECT"
selObjs = miscFunc.getSelObjsFromOutlinerAndViewport(self, context, modeAtBegin)
for obj in selObjs:
scene.ntzSmFrm.templatedObjects.add(obj.name)
templateEnabled = False
try:
if obj['ntzSmFrm_template']:
objIsTemplate = True
except:
pass
if not templateEnabled:
obj['ntzSmFrm_originalDisplay'] = obj.display_type
obj.display_type = 'WIRE'
obj.hide_select = True
obj['ntzSmFrm_template'] = 1
#Templated
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Toggle Template of objects highlighted in outliner
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_toggle_template(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_toggle_template"
bl_label = 'NTZSF : Template'
bl_description = 'Toggles object(s) between template and non template'
bl_options = {'REGISTER', 'UNDO'}
tooltip: bpy.props.StringProperty()
makeSelectable : BoolProperty (
name="Make Template Selectable",
description="Make the template object selectable (Default = False)",
default = False
)
@classmethod
def poll(cls, context):
return True
@classmethod
def description(cls, context, properties):
return properties.tooltip
def draw(self, context):
scene = context.scene
lay = self.layout.column(align=True)
lay.prop(self, 'makeSelectable')
#END draw()
def execute(self, context):
scene = context.scene
modeAtBegin = "Unknown" #declare
try:
#try to determine objectMode
modeAtBegin = bpy.context.object.mode
except:
modeAtBegin = "OBJECT"
selObjs = miscFunc.getSelObjsFromOutlinerAndViewport(self, context, modeAtBegin)
if modeAtBegin == "OBJECT":
if len(selObjs) > 0:
for obj in selObjs:
bpy.context.view_layer.objects.active = obj
break
for obj in selObjs:
objIsTemplate = False #declare
try:
if obj['ntzSmFrm_template']:
objIsTemplate = True
except:
pass
if objIsTemplate:
bpy.ops.view3d.ntzsf_untemplate_specific_obj(objectToUntemplate = f"{obj.name}" )
else:
bpy.ops.view3d.ntzsf_template_specific_obj(objectToTemplate = f"{obj.name}", makeSelectable = self.makeSelectable )
#Templated
return {'FINISHED'}
# END execute()
def invoke(self, context, event):
addonPrefs = context.preferences.addons[__package__].preferences
if addonPrefs.defaultTemplateSelectableState == "UNSELECTABLE":
self.makeSelectable = False
elif addonPrefs.defaultTemplateSelectableState == "SELECTABLE":
self.makeSelectable = True
return self.execute(context)
#END invoke()
# END Operator()
# -----------------------------------------------------------------------------
# Refresh Templated Objects List
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_refresh_template_objs(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_refresh_template_objs"
bl_label = 'NTZSF : Refresh "Templated Obj List"'
bl_description = 'Refresh the list of templated objects'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scene = context.scene
objs = [obj for obj in bpy.context.scene.objects]
scene.ntzSmFrm.templatedObjects.clear()
for obj in objs:
try:
if obj['ntzSmFrm_template']:
scene.ntzSmFrm.templatedObjects.add(obj.name)
except:
pass
#Refreshed Template Objects
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Un-Template Highlighted Objects in the Outliner
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_untemplate_objs(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_untemplate_objs"
bl_label = 'NTZSF : Remove obj from "Templated Obj List"'
bl_description = 'Remove the templated object'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scene = context.scene
selObjsInOutliner = [] #declare
# Select objects in outliner
area = None #declare
try:
#check for outliner in the main window
area = next(a for a in context.screen.areas if a.type == 'OUTLINER')
except:
try:
#check for outliner in other windows
area = next(a for w in context.window_manager.windows
for a in w.screen.areas if a.type == 'OUTLINER')
except:
pass
if area is not None:
sel_org = context.selected_objects[:]
objs = context.view_layer.objects
hide_select = {o for o in objs if o.hide_select}
for o in hide_select: # Toggle off hide select
o.hide_select = False
for o in sel_org: # Deselect all selected
o.select_set(False)
bpy.ops.outliner.object_operation({'area': area}, type='SELECT')
selObjsInOutliner = context.selected_objects[:]
# Toggle on hide select for objects not selected in outliner
for o in hide_select:
if not o.select_get():
o.hide_select = True
for o in sel_org: # Restore original selection
o.select_set(True)
# BEGIN code that un-templates the object
for obj in selObjsInOutliner:
templateEnabled = obj.pop("ntzSmFrm_template", False)
originalDisplay = obj.pop('ntzSmFrm_originalDisplay', "SOLID")
if templateEnabled:
obj.display_type = originalDisplay
obj.hide_select = False
scene.ntzSmFrm.templatedObjects.discard( f"{obj.name}" )
# END code that un-templates the object
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Template Specific Obj
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_template_specific_obj(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_template_specific_obj"
bl_label = 'NTZSF : Add specific obj from "Templated Obj List"'
bl_description = 'Add specific object from templated object list'
bl_options = {'REGISTER', 'UNDO'}
objectToTemplate : StringProperty(
name="Object to Template",
description="Name of the Object to Template (Default = None)",
default = "None"
)
makeSelectable : BoolProperty (
name="Make Template Selectable",
description="Make the template object selectable (Default = False)",
default = False
)
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scene = context.scene
# BEGIN code that templates the object
obj = None #declare
try:
obj = bpy.data.objects[self.objectToTemplate]
except:
pass
if obj is not None:
scene.ntzSmFrm.templatedObjects.add(obj.name)
templateEnabled = False
try:
if obj['ntzSmFrm_template']:
templateEnabled = True
except:
pass
if not templateEnabled:
obj['ntzSmFrm_originalDisplay'] = obj.display_type
obj.display_type = 'WIRE'
obj.hide_select = not(self.makeSelectable)
obj['ntzSmFrm_template'] = 1
# END code that templates the object
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Un-Template Specific Obj
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_untemplate_specific_obj(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_untemplate_specific_obj"
bl_label = 'NTZSF : Remove specific obj from "Templated Obj List"'
bl_description = 'Remove specific object from templated object list'
bl_options = {'REGISTER', 'UNDO'}
objectToUntemplate : StringProperty(
name="Object to Remove",
description="Name of the Object to remove (Default = None)",
default = "None"
)
@classmethod
def poll(cls, context):
return True
def draw(self, context):
pass
#END draw()
def execute(self, context):
scene = context.scene
# BEGIN code that un-templates the object
obj = None #declare
try:
obj = bpy.data.objects[self.objectToUntemplate]
except:
pass
if obj is not None:
templateEnabled = obj.pop("ntzSmFrm_template", False)
originalDisplay = obj.pop('ntzSmFrm_originalDisplay', "SOLID")
if templateEnabled:
obj.display_type = originalDisplay
obj.hide_select = False
scene.ntzSmFrm.templatedObjects.discard( self.objectToUntemplate )
# END code that un-templates the object
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Clear all Templated Objects
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_clear_all_template_objs(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_clear_all_template_objs"
bl_label = 'NTZSF : Clear "Templated Obj List"'
bl_description = 'Clear the list of templated objects'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scene = context.scene
objs = [obj for obj in bpy.context.scene.objects]
scene.ntzSmFrm.templatedObjects.clear()
for obj in objs:
templateEnabled = obj.pop("ntzSmFrm_template", False)
originalDisplay = obj.pop('ntzSmFrm_originalDisplay', "SOLID")
if templateEnabled:
obj.display_type = originalDisplay
obj.hide_select = False
#Cleared Template Objects
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Make all existing template objects selectable
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_change_template_selection_state(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_change_template_selection_state"
bl_label = 'NTZSF : Change All Template Selection State'
bl_description = 'Change All Template Selection State'
bl_options = {'REGISTER', 'UNDO'}
makeSelectable : BoolProperty(
name="Make All Objects Selectable",
description="Make All Objects Selectable",
default = True
)
@classmethod
def poll(cls, context):
return True
def execute(self, context):
#refresh templated obj list
bpy.ops.view3d.ntzsf_refresh_template_objs()
scene = context.scene
objs = [obj for obj in bpy.context.scene.objects]
for obj in objs:
templateEnabled = False
try:
if obj['ntzSmFrm_template']:
templateEnabled = True
except:
pass
if templateEnabled:
if self.makeSelectable:
obj.hide_select = False
else:
obj.hide_select = True
#Cleared Template Objects
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Select Object by Name
# -----------------------------------------------------------------------------
class VIEW3D_OT_ntzsf_sel_obj_by_name(Operator):
"""Tooltip"""
bl_idname = "view3d.ntzsf_sel_obj_by_name"
bl_label = 'NTZSF : Select Object'
bl_description = 'Selects and object by name'
bl_options = {'REGISTER', 'UNDO'}
objToSelect : StringProperty(
name="Object to Select",
description="Name of the Object to Select (Default = None)",
default = "None"
)
@classmethod
def poll(cls, context):
return True
def draw(self, context):
pass
#END draw()
def execute(self, context):
scene = context.scene
modeAtBegin = "Unknown" #declare
try:
#try to determine objectMode
modeAtBegin = bpy.context.object.mode
except:
modeAtBegin = "OBJECT"
obj = None
try:
obj = bpy.data.objects[self.objToSelect]
except:
pass
if obj is not None:
if modeAtBegin == "EDIT":
bpy.ops.object.mode_set(mode = 'OBJECT') #switch to object mode
bpy.ops.object.select_all(action='DESELECT') #deselect all objs
obj.select_set(True) #select object
bpy.context.view_layer.objects.active = obj #set obj as active obj
return {'FINISHED'}
# END execute()
# END Operator()