-
Notifications
You must be signed in to change notification settings - Fork 1
/
matchrendervisibility105_1.py
258 lines (210 loc) · 8.99 KB
/
matchrendervisibility105_1.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
################### About ###################
# I made these little entries to streamline the workflow of visibility and rendering,
# because when working with many objects, the render visibilty sometimes is not the
# same as the viewport visibility, and when you hit render, things are hidden or shown
# accidentally, ruining good renders. This is a quality check UX.
# To update the viewport to final render or vice versa (render to viewport),
# you can use the script to see what is what for final render.
# Update: fixed a blender registration bug to make it compatible to BFA
################### Preliminary Information ###################
bl_info = {
"name": "Match Render Visibility",
"author": "Andres (Draise) Stephens",
"version": (1, 0, 5),
"blender": (2, 80, 0),
"location": "View3D > Properties Shelf > View > Viewport to Render Visibility",
"description": "Operators to Show Render only and other visibility matching controls.",
"warning": "",
"doc_url": "https://github.com/Draise14/Addon-Match-to-Render",
"category": "View",
}
import bpy
from bpy.types import (
Header,
Menu,
Panel,
BoolProperty,
)
################### Operators ###################
# First Operator
class VIEW3D_OT_update_view_to_render(bpy.types.Operator):
"""Match all visibility toggles to render visibility
This includes Collections"""
bl_idname = "update_view_to_render.renderto"
bl_label = "Match to Render"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
print("Operator is executing")
for x in bpy.data.objects:
print(x, "listed")
if x.hide_render == True:
x.hide_viewport = True
x.hide_set(True)
else:
if x.hide_render == False:
x.hide_viewport = False
x.hide_set(False)
for modifier in x.modifiers:
modifier.show_viewport = modifier.show_render
for x in bpy.data.collections:
if x.hide_render == True:
x.hide_viewport = True
else:
if x.hide_render == False:
x.hide_viewport = False
print("Operator Finished, now all is set")
return {'FINISHED'}
# Second Operator
class VIEW3D_OT_update_render_to_view(bpy.types.Operator):
"""Match all visibility toggles to viewport visibility
This includes Collections"""
bl_idname = "update_view_to_render.viewto"
bl_label = "Match to Viewport"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
print("Operator is executing")
for x in bpy.data.objects:
print(x, "listed")
if x.hide_viewport == True:
x.hide_render = True
x.hide_set(True)
print (x, "render to view done")
else:
if x.hide_viewport == False:
x.hide_render = False
x.hide_set(False)
print (x, "visibility is True")
for modifier in x.modifiers:
modifier.show_render = modifier.show_viewport
for x in bpy.data.collections:
if x.hide_viewport == True:
x.hide_render = True
#print (x, "view to render done")
else:
if x.hide_viewport == False:
x.hide_render = False
print("Operator Finished, now all is set")
return {'FINISHED'}
# Third Operator
class VIEW3D_OT_gethide(bpy.types.Operator):
"""Match all visibility toggles to hide visibility
This doesn't affect Collection"""
bl_idname = "update_view_to_render.gethide"
bl_label = "Match to Hidden"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
print("Operator is executing")
for x in bpy.data.objects:
#print(x, x.hide_get())
if x.hide_get() == True:
x.hide_viewport = True
x.hide_render = True
else:
if x.hide_get() == False:
x.hide_viewport = False
x.hide_render = False
for x in bpy.data.objects:
#print(x, x.hide_get())
if x.hide_get() == True:
x.hide_viewport = True
x.hide_render = True
else:
if x.hide_get() == False:
x.hide_viewport = False
x.hide_render = False
print("Operator Finished, now all is set - except for those pesky collection hide toggles")
return {'FINISHED'}
# Fourth Operator
class VIEW3D_OT_showrender(bpy.types.Operator):
"""Show Render Result in Viewport"""
bl_idname = "update_view_to_render.showrender"
bl_label = "Show Render in Viewport"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
print("Operator is executing")
for x in bpy.data.objects:
bpy.context.space_data.overlay.show_overlays = False
bpy.context.space_data.shading.type = 'RENDERED'
bpy.context.space_data.show_gizmo = False
if x.hide_render == True:
x.hide_viewport = True
x.hide_set(True)
else:
if x.hide_render == False:
x.hide_viewport = False
x.hide_set(False)
for x in bpy.data.collections:
if x.hide_render == True:
x.hide_viewport = True
else:
if x.hide_render == False:
x.hide_viewport = False
return {'FINISHED'}
################### Register the Submenu UI entries ###################
class OUTLINER_MT_renderview(Menu):
bl_label = "Match Render Visibility"
def draw(self, context):
layout = self.layout
# NOTE: I'd love to control the 3D view "Show Render Only" from here, but not sure how.
# Might add an option in the addon later to control where you'd like to add this menu, if in the 3D View with the other operator, or here in the outliner where it would make sense - yet still be able to control the viewport.
#layout.operator(VIEW3D_OT_showrender.bl_idname, text="Show Render Only", icon = "OVERLAY")
layout.separator()
layout.operator(VIEW3D_OT_update_view_to_render.bl_idname, text="from Render", icon = "RESTRICT_RENDER_OFF")
layout.operator(VIEW3D_OT_update_render_to_view.bl_idname, text="from Viewport", icon = "RESTRICT_VIEW_OFF")
layout.operator(VIEW3D_OT_gethide.bl_idname, text="from Hidden", icon = "HIDE_OFF")
################### Register the UI entries ###################
# Panel Entries in Properties Shelf
class VIEW3D_PT_rendervisibility(bpy.types.Panel):
bl_idname = "VIEW3D_PT_update_view_to_render"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "View"
bl_label = "Render Visibility"
def draw(self, context):
layout = self.layout
# Show Render Button
row = layout.row()
row.operator(VIEW3D_OT_showrender.bl_idname, text="Show Render Only", icon = "OVERLAY")
# Math From Box
box = layout.box()
col = box.column(align=True)
col.label(text="Match from:")
layout.use_property_split = False
col.operator(VIEW3D_OT_update_view_to_render.bl_idname, text="Render", icon = "RESTRICT_RENDER_OFF")
col.operator(VIEW3D_OT_update_render_to_view.bl_idname, text="Viewport", icon = "RESTRICT_VIEW_OFF")
col.operator(VIEW3D_OT_gethide.bl_idname, text="Hidden", icon = "HIDE_OFF")
# Header Entries in Outliner
def drawmenu(self, context):
layout = self.layout
layout.separator()
layout.menu("OUTLINER_MT_renderview")
################### Classes ###################
# ------------------- Registering classes. The classes tuple.
classes = (
VIEW3D_OT_update_view_to_render,
VIEW3D_OT_update_render_to_view,
VIEW3D_OT_gethide,
VIEW3D_OT_showrender,
OUTLINER_MT_renderview,
VIEW3D_PT_rendervisibility,
)
# ------------------- Register Unregister
def register():
bpy.utils.register_class(VIEW3D_OT_update_view_to_render)
bpy.utils.register_class(VIEW3D_OT_update_render_to_view)
bpy.utils.register_class(VIEW3D_OT_gethide)
bpy.utils.register_class(VIEW3D_OT_showrender)
bpy.utils.register_class(OUTLINER_MT_renderview)
bpy.utils.register_class(VIEW3D_PT_rendervisibility)
bpy.types.OUTLINER_PT_filter.prepend(drawmenu)
def unregister():
bpy.utils.unregister_class(VIEW3D_OT_update_view_to_render)
bpy.utils.unregister_class(VIEW3D_OT_update_render_to_view)
bpy.utils.unregister_class(VIEW3D_OT_gethide)
bpy.utils.unregister_class(VIEW3D_OT_showrender)
bpy.utils.unregister_class(OUTLINER_MT_renderview)
bpy.utils.unregister_class(VIEW3D_PT_rendervisibility)
bpy.types.OUTLINER_PT_filter.remove(drawmenu)
# For scripting only
if __name__ == "__main__":
register()