-
Notifications
You must be signed in to change notification settings - Fork 0
/
hideObjectsFromRays_05.py
93 lines (67 loc) · 2.41 KB
/
hideObjectsFromRays_05.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
bl_info = {
"name": "Show and hide",
"author": "Fredrik Svärd",
"version": (0,6),
"blender": (3,4,1),
"location": "View 3D > Tool",
"warning": "",
"wiki_url":"",
"category": "Custom tools",
}
import bpy
from bpy.types import (Panel, Operator)
# ------------------------------------------------------------------------
# Operators
# ------------------------------------------------------------------------
class HideOperator(Operator):
bl_idname = "object.hide_operator"
bl_label = "Hide Object Operator"
def execute(self, context):
for c in bpy.context.collection:
for o in c.objects:
if o.type == "MESH":
o.visible_camera = False
return {'FINISHED'}
class ShowOperator(Operator):
bl_idname = "object.show_operator"
bl_label = "Show Object Operator"
def execute(self, context):
for c in bpy.context.collection:
for o in c.objects:
if o.type == "MESH":
o.visible_camera = True
return {'FINISHED'}
# ------------------------------------------------------------------------
# Panel in Object Mode
# ------------------------------------------------------------------------
class OBJECT_PT_CustomPanel(Panel):
bl_idname = "object.custom_panel"
bl_label = "NJORD"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Show / Hide"
bl_context = "objectmode"
@classmethod
def poll(self,context):
return context.object is not None
def draw(self, context):
layout = self.layout
obj = context.object
layout.label(text="Show/Hide, Camera Rays.")
col = layout.column(align=True)
col.operator(HideOperator.bl_idname, text="Hide", icon="CONSOLE")
col.operator(ShowOperator.bl_idname, text="Show", icon="CONSOLE")
layout.separator()
# ------------------------------------------------------------------------
# Registration
# ------------------------------------------------------------------------
def register():
bpy.utils.register_class(OBJECT_PT_CustomPanel)
bpy.utils.register_class(HideOperator)
bpy.utils.register_class(ShowOperator)
def unregister():
bpy.utils.unregister_class(OBJECT_PT_CustomPanel)
bpy.utils.unregister_class(HideOperator)
bpy.utils.unregister_class(ShowOperator)
if __name__ == "__main__":
register()