-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathop_set_obj.py
146 lines (111 loc) · 4.74 KB
/
op_set_obj.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
import bpy
class VIEW_OT_set_active_obj(bpy.types.Operator):
""" Click to select obj and set as active obj
Ctrl to deselect"""
bl_idname = "view.set_active_obj"
bl_label = "Set Active Object"
bl_options = {'INTERNAL', 'UNDO'}
# bl_options = {'INTERNAL'}
obj_name: bpy.props.StringProperty(name="Name")
def invoke(self, context, event):
obj = bpy.data.objects[self.obj_name]
if event.ctrl:
obj.select_set(False)
else:
context.view_layer.objects.active = obj
obj.select_set(True)
return {'FINISHED'}
# select obj by lightgroup
class VIEW_OT_select_obj_by_lightgroup(bpy.types.Operator):
""" Select obj by lightgroup """
bl_idname = "view.select_obj_by_lightgroup"
bl_label = "Select Object by Lightgroup"
bl_options = {'INTERNAL', 'UNDO'}
lightgroup: bpy.props.StringProperty(name="Lightgroup")
def invoke(self, context, event):
for obj in bpy.data.objects:
if obj.lightgroup == self.lightgroup:
obj.select_set(True)
return {'FINISHED'}
# set lightgroup object visibility
class VIEW_OT_toggle_lightgroup_visibility(bpy.types.Operator):
""" Toggle lightgroup object visibility """
bl_idname = "view.toggle_lightgroup_visibility"
bl_label = "Toggle Lightgroup Visibility"
bl_options = {'INTERNAL', 'UNDO'}
lightgroup: bpy.props.StringProperty(name="Lightgroup")
def invoke(self, context, event):
from .ui import get_obj_list_in_lightgroup
fit_list = get_obj_list_in_lightgroup(self.lightgroup)
vis = not fit_list[0].hide_viewport
for obj in fit_list:
obj.hide_viewport = vis
obj.hide_render = vis
return {'FINISHED'}
# solo lightgroup object
class VIEW_OT_solo_lightgroup_object(bpy.types.Operator):
bl_idname = "view.solo_lightgroup_object"
bl_label = "Solo Lightgroup Object"
bl_option = {'INTERNAL', 'UNDO'}
lightgroup: bpy.props.StringProperty(name="Lightgroup")
def execute(self, context):
# get all lightgroup objects
from .ui import get_obj_list_in_lightgroup
for lightgroup_item in context.view_layer.lightgroups:
obj_list = get_obj_list_in_lightgroup(lightgroup_item.name)
if lightgroup_item.name != self.lightgroup:
for obj in obj_list:
obj.hide_viewport = True
obj.hide_render = True
else:
for obj in obj_list:
obj.hide_viewport = False
obj.hide_render = False
return {'FINISHED'}
# solo light in lightgroup
class VIEW_OT_solo_light_in_lightgroup(bpy.types.Operator):
bl_idname = "view.solo_light_in_lightgroup"
bl_label = "Solo Light in Lightgroup"
bl_option = {'INTERNAL', 'UNDO'}
lightgroup: bpy.props.StringProperty(name="Lightgroup")
obj_name: bpy.props.StringProperty(name="Object Name")
def execute(self, context):
# get objects with lightgroup
from .ui import get_obj_list_in_lightgroup
fit_list = get_obj_list_in_lightgroup(self.lightgroup)
for obj in fit_list:
if obj.name != self.obj_name:
obj.hide_viewport = True
obj.hide_render = True
else:
obj.hide_viewport = False
obj.hide_render = False
return {'FINISHED'}
# reset all solo with light group
class VIEW_OT_reset_solo_lightgroup(bpy.types.Operator):
bl_idname = "view.reset_solo_lightgroup"
bl_label = "Reset Solo"
bl_option = {'INTERNAL', 'UNDO'}
def execute(self, context):
# get all lightgroup objects
from .ui import get_obj_list_in_lightgroup
for lightgroup_item in context.view_layer.lightgroups:
obj_list = get_obj_list_in_lightgroup(lightgroup_item.name)
for obj in obj_list:
obj.hide_viewport = False
obj.hide_render = False
return {'FINISHED'}
def register():
bpy.utils.register_class(VIEW_OT_set_active_obj)
bpy.utils.register_class(VIEW_OT_select_obj_by_lightgroup)
bpy.utils.register_class(VIEW_OT_toggle_lightgroup_visibility)
bpy.utils.register_class(VIEW_OT_solo_lightgroup_object)
bpy.utils.register_class(VIEW_OT_solo_light_in_lightgroup)
bpy.utils.register_class(VIEW_OT_reset_solo_lightgroup)
def unregister():
bpy.utils.unregister_class(VIEW_OT_set_active_obj)
bpy.utils.unregister_class(VIEW_OT_select_obj_by_lightgroup)
bpy.utils.unregister_class(VIEW_OT_toggle_lightgroup_visibility)
bpy.utils.unregister_class(VIEW_OT_solo_lightgroup_object)
bpy.utils.unregister_class(VIEW_OT_solo_light_in_lightgroup)
bpy.utils.unregister_class(VIEW_OT_reset_solo_lightgroup)