-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhiderender.py
84 lines (65 loc) · 2.4 KB
/
hiderender.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
bl_info = {
"name": "Hide Render",
"category": "3D View",
"author": "Emils Geršisnskis - Ješinskis / EMILSVFX",
"blender": (2,80,0),
"location": "View3D",
"description":"Hide an object from viewport when render toggle is off",
"warning": "",
"wiki_url":"https://github.com/emilsvfx/hideRender",
"version":(1,0,2)
}
import bpy
# Constants
HIDE_VIEWPORT = "hide_viewport"
HIDE_RENDER = "hide_render"
def add_viewport_hide_driver(obj):
# Adds a driver to the 'hide_viewport' property of the object.
# The driver controls the property based on the object's 'hide_render' property.
try:
view = obj.driver_add(HIDE_VIEWPORT)
except Exception as e:
print(f"Failed to add driver to object {obj.name}: {e}")
return
drv = view.driver
drv.type = "AVERAGE"
hide_render_var = drv.variables.new()
hide_render_var.name = HIDE_RENDER
hide_render_var.type = 'SINGLE_PROP'
hide_render_var.targets[0].id_type = 'OBJECT'
hide_render_var.targets[0].id = obj
hide_render_var.targets[0].data_path = HIDE_RENDER
def main(context):
# Processes all selected objects in the current context
# and adds a viewport hide driver to them.
sel_objs = bpy.context.selected_objects
for obj in sel_objs:
add_viewport_hide_driver(obj)
class SimpleOperator(bpy.types.Operator):
# Blender Operator that hides selected objects in the viewport when the render toggle is off.
bl_idname = "object.simple_operator"
bl_label = "Hide Render"
def execute(self, context):
main(context)
return {'FINISHED'}
class LayoutDemoPanel(bpy.types.Panel):
# Blender Panel that provides a UI for the Hide Render operator in the 3D Viewport.
bl_idname = "hide_render"
bl_label = "Hide Render"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "View"
def draw(self, context):
layout = self.layout
layout.label(text="Hide Render:")
row = layout.row()
row.scale_y = 2.0
row.operator("object.simple_operator")
def register():
bpy.utils.register_class(SimpleOperator)
bpy.utils.register_class(LayoutDemoPanel)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
bpy.utils.unregister_class(LayoutDemoPanel)
if __name__ == "__main__":
register()