Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
101 lines (74 loc) · 2.5 KB
/
Copy path__init__.py
File metadata and controls
101 lines (74 loc) · 2.5 KB
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
import bpy
import random
from bpy.types import (Operator, Panel)
from itertools import cycle
bl_info = {
"name": "Collections Color Random",
"author": "Jorge Hernandez Melendez",
"version": (0, 3),
"blender": (2, 91, 0),
"location": "",
"description": "Random colors for all Collections",
"warning": "",
"wiki_url": "",
"category": "Interface",
}
class RandomColorCollections(Operator):
bl_idname = "randcol.collections"
bl_label = "Random Color for Collections"
bl_description = "Random colors for all Collections"
def execute(self, context):
# Blender 2.91.0 Alpha
# Random color for all collections
colors = []
used_colors = []
hardcoded_bcolors = 8
# recreamos un array con los colores hardcoded que trae blende
# por ahora trae 8 colores
for i in range(hardcoded_bcolors):
colors.append('COLOR_' + str(i + 1).zfill(2))
if bpy.types.WindowManager.random_color_collections_toggle % 2 == 0:
pool = cycle(colors)
bpy.types.WindowManager.random_color_collections_toggle = 1
else:
pool = cycle(colors[::-1])
bpy.types.WindowManager.random_color_collections_toggle = 0
for col in bpy.data.collections:
color = next(pool)
col.color_tag = color
for area in bpy.context.screen.areas:
if area.type == 'OUTLINER':
area.tag_redraw()
return {'FINISHED'}
class RC_PT_Collections(Panel):
bl_label = "Random Color for Collections"
bl_category = "Random Color Collections"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
flow = layout.grid_flow(align=True)
col = flow.column()
# col = layout.box()
col.operator(
"randcol.collections",
text="Random Colors for all Collections"
)
all_classes = [
RandomColorCollections,
RC_PT_Collections
]
def register():
from bpy.utils import register_class
for cls in all_classes:
register_class(cls)
bpy.types.WindowManager.random_color_collections_toggle = 0
def unregister():
from bpy.utils import unregister_class
for cls in reversed(all_classes):
unregister_class(cls)
del bpy.types.WindowManager.random_color_collections_toggle
if __name__ == "__main__":
register()