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
|
# SPDX-License-Identifier: GPL-2.0-or-later
# ############################################################
# Importing - Same For All Render Layer Tests
# ############################################################
import unittest
import os
import sys
from view_layer_common import *
# ############################################################
# Testing
# ############################################################
class UnitTesting(ViewLayerTesting):
def test_shared_layer_collections_copy_full(self):
"""
See if scene copying 'FULL_COPY' is keeping collections visibility
and selectability.
"""
import os
import bpy
scene = bpy.context.scene
enabled_lookup = [True, False, False, True]
enabled_lookup_sub = [False, True, False]
selectable_lookup = [True, True, False, False]
selectable_lookup_sub = [False, True, False, True]
new_collections = []
# clean everything
for layer in scene.view_layers:
while layer.collections:
layer.collections.unlink(layer.collections[0])
# create new collections
for i in range(4):
collection = scene.master_collection.collections.new(str(i))
new_collections.append(collection)
for j in range(3):
sub_collection = collection.collections.new("{0}:{1}".format(i, j))
# link to the original scene
for layer in scene.view_layers:
for i, collection in enumerate(new_collections):
layer.collections.link(collection)
self.assertEqual(layer.collections[-1], layer.collections[i])
layer.collections[i].enabled = enabled_lookup[i]
layer.collections[i].selectable = selectable_lookup[i]
for j, sub_collection in enumerate(layer.collections[i].collections):
sub_collection.enabled = enabled_lookup_sub[j]
sub_collection.selectable = selectable_lookup_sub[j]
# copy scene
bpy.ops.scene.new(type='FULL_COPY')
new_scene = bpy.context.scene
self.assertNotEqual(scene, new_scene)
# update depsgrah
for view_layer in scene.view_layers:
view_layer.update() # update depsgraph
# compare scenes
for h, layer in enumerate(scene.view_layers):
new_layer = new_scene.view_layers[h]
for i, collection in enumerate(layer.collections):
new_collection = new_layer.collections[i]
self.assertEqual(collection.enabled, new_collection.enabled)
self.assertEqual(collection.selectable, new_collection.selectable)
for j, sub_collection in enumerate(layer.collections[i].collections):
new_sub_collection = new_collection.collections[j]
self.assertEqual(sub_collection.enabled, new_sub_collection.enabled)
self.assertEqual(sub_collection.selectable, new_sub_collection.selectable)
# ############################################################
# Main - Same For All Render Layer Tests
# ############################################################
if __name__ == '__main__':
UnitTesting._extra_arguments = setup_extra_arguments(__file__)
unittest.main()
|