test_group_e.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_group_delete_object(self):
  13. """
  14. See if we can safely remove instanced objects
  15. """
  16. import bpy
  17. scene = bpy.context.scene
  18. view_layer = bpy.context.view_layer
  19. ob = bpy.context.object
  20. # clean up the scene a bit
  21. for o in (o for o in view_layer.objects if o != ob):
  22. view_layer.collections[0].collection.objects.unlink(o)
  23. for v in (v for v in scene.view_layers if v != view_layer):
  24. scene.view_layers.remove(v)
  25. # update depsgraph
  26. view_layer.update()
  27. # create group
  28. group = bpy.data.groups.new("Switch")
  29. group.objects.link(ob)
  30. # update depsgraph
  31. view_layer.update()
  32. # instance the group
  33. empty = bpy.data.objects.new("Empty", None)
  34. bpy.context.scene_collection.objects.link(empty)
  35. layer_collection = bpy.context.layer_collection
  36. empty.instance_type = 'GROUP'
  37. empty.instance_collection = group
  38. # prepare to delete the original object
  39. # we could just pass an overridden context
  40. # but let's do it the old fashion way
  41. view_layer.objects.active = ob
  42. ob.select_set(True)
  43. self.assertTrue(ob.select_get())
  44. empty.select_set(False)
  45. self.assertFalse(empty.select_get())
  46. # update depsgraph
  47. view_layer.update()
  48. # delete the original object
  49. bpy.ops.object.delete()
  50. # ############################################################
  51. # Main - Same For All Render Layer Tests
  52. # ############################################################
  53. if __name__ == '__main__':
  54. UnitTesting._extra_arguments = setup_extra_arguments(__file__)
  55. unittest.main()