/
collection_quickies.py
66 lines (44 loc) · 1.51 KB
/
collection_quickies.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
# GPL blahblah do whatever you want with this
bl_info = {
"name": "Collectioranth",
"author": "Pablo Vazquez",
"version": (0, 1),
"blender": (2, 80),
"location": "Header of the 3D View",
"description": "2.7 Style Collection Browser",
"category": "Scene"}
import bpy
from bpy.types import Operator
from bpy.props import BoolProperty
def view3d_header_collections(self, context):
layout = self.layout
collections = bpy.data.collections
act_ob = context.active_object
idx = 1
split = layout.split()
col = split.column(align=True)
row = col.row(align=True)
row.scale_y = 0.5
for coll in bpy.data.collections:
# If there are icons, use LAYER_USED
icon = 'LAYER_USED' if len(coll.objects) > 0 else 'BLANK1'
# if the active object is in the current collection
if act_ob and (coll in act_ob.users_collection):
icon = 'LAYER_ACTIVE'
props = row.operator('object.hide_collection', text='', icon=icon)
props.collection_index = idx
if idx%5==0:
row = col.row(align=True)
row.scale_y = 0.5
if idx%10==0:
layout.separator()
col = layout.column(align=True)
row = col.row(align=True)
row.scale_y = 0.5
idx += 1
def register():
bpy.types.VIEW3D_HT_header.append(view3d_header_collections)
def unregister():
bpy.types.VIEW3D_HT_header.remove(view3d_header_collections)
if __name__ == "__main__":
register()