test_scene_copy_f.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # ############################################################
  2. # Importing - Same For All Render Layer Tests
  3. # ############################################################
  4. import unittest
  5. import os
  6. import sys
  7. from view_layer_common import *
  8. # ############################################################
  9. # Testing
  10. # ############################################################
  11. class UnitTesting(ViewLayerTesting):
  12. def test_shared_layer_collections_copy_full(self):
  13. """
  14. See if scene copying 'FULL_COPY' is keeping collections visibility
  15. and selectability.
  16. """
  17. import os
  18. import bpy
  19. scene = bpy.context.scene
  20. enabled_lookup = [True, False, False, True]
  21. enabled_lookup_sub = [False, True, False]
  22. selectable_lookup = [True, True, False, False]
  23. selectable_lookup_sub = [False, True, False, True]
  24. new_collections = []
  25. # clean everything
  26. for layer in scene.view_layers:
  27. while layer.collections:
  28. layer.collections.unlink(layer.collections[0])
  29. # create new collections
  30. for i in range(4):
  31. collection = scene.master_collection.collections.new(str(i))
  32. new_collections.append(collection)
  33. for j in range(3):
  34. sub_collection = collection.collections.new("{0}:{1}".format(i, j))
  35. # link to the original scene
  36. for layer in scene.view_layers:
  37. for i, collection in enumerate(new_collections):
  38. layer.collections.link(collection)
  39. self.assertEqual(layer.collections[-1], layer.collections[i])
  40. layer.collections[i].enabled = enabled_lookup[i]
  41. layer.collections[i].selectable = selectable_lookup[i]
  42. for j, sub_collection in enumerate(layer.collections[i].collections):
  43. sub_collection.enabled = enabled_lookup_sub[j]
  44. sub_collection.selectable = selectable_lookup_sub[j]
  45. # copy scene
  46. bpy.ops.scene.new(type='FULL_COPY')
  47. new_scene = bpy.context.scene
  48. self.assertNotEqual(scene, new_scene)
  49. # update depsgrah
  50. for view_layer in scene.view_layers:
  51. view_layer.update() # update depsgraph
  52. # compare scenes
  53. for h, layer in enumerate(scene.view_layers):
  54. new_layer = new_scene.view_layers[h]
  55. for i, collection in enumerate(layer.collections):
  56. new_collection = new_layer.collections[i]
  57. self.assertEqual(collection.enabled, new_collection.enabled)
  58. self.assertEqual(collection.selectable, new_collection.selectable)
  59. for j, sub_collection in enumerate(layer.collections[i].collections):
  60. new_sub_collection = new_collection.collections[j]
  61. self.assertEqual(sub_collection.enabled, new_sub_collection.enabled)
  62. self.assertEqual(sub_collection.selectable, new_sub_collection.selectable)
  63. # ############################################################
  64. # Main - Same For All Render Layer Tests
  65. # ############################################################
  66. if __name__ == '__main__':
  67. UnitTesting._extra_arguments = setup_extra_arguments(__file__)
  68. unittest.main()