Fix (unreported) missing updates in scripts/docs after scene.update() removal.

This should really have been done together with API changes, simple
usage of grep does the trick to catch most places needing updates.
This commit is contained in:
Bastien Montagne
2019-06-04 14:36:53 +02:00
parent 1d2e4c44bd
commit 33e8db94b1
25 changed files with 41 additions and 40 deletions

View File

@@ -102,16 +102,16 @@ To avoid expensive recalculations every time a property is modified,
Blender defers making the actual calculations until they are needed. Blender defers making the actual calculations until they are needed.
However, while the script runs you may want to access the updated values. However, while the script runs you may want to access the updated values.
In this case you need to call :class:`bpy.types.Scene.update` after modifying values, for example: In this case you need to call :class:`bpy.types.ViewLayer.update` after modifying values, for example:
.. code-block:: python .. code-block:: python
bpy.context.object.location = 1, 2, 3 bpy.context.object.location = 1, 2, 3
bpy.context.scene.update() bpy.context.view_layer.update()
Now all dependent data (child objects, modifiers, drivers... etc) Now all dependent data (child objects, modifiers, drivers... etc)
has been recalculated and is available to the script. has been recalculated and is available to the script within active view layer.
Can I redraw during the script? Can I redraw during the script?

View File

@@ -160,7 +160,8 @@ class BPyOpsSubModOp:
else: else:
import bpy import bpy
for scene in bpy.data.scenes: for scene in bpy.data.scenes:
scene.update() for view_layer in scene.view_layers:
view_layer.update()
__doc__ = property(_get_doc) __doc__ = property(_get_doc)

View File

@@ -48,7 +48,7 @@ def example_function(text, save_path, render_path):
scene.collection.objects.link(light_ob) scene.collection.objects.link(light_ob)
light_ob.location = 2.0, 2.0, 5.0 light_ob.location = 2.0, 2.0, 5.0
scene.update() bpy.context.view_layer.update()
if save_path: if save_path:
bpy.ops.wm.save_as_mainfile(filepath=save_path) bpy.ops.wm.save_as_mainfile(filepath=save_path)

View File

@@ -25,7 +25,7 @@ class UnitTesting(ViewLayerTesting):
bpy.context.window.scene = main_scene bpy.context.window.scene = main_scene
# Update depsgraph. # Update depsgraph.
main_scene.update() bpy.context.view_layer.update()
# Safety check, there should be no objects in thew newly created scene. # Safety check, there should be no objects in thew newly created scene.
self.assertEqual(0, len(bpy.context.depsgraph.objects)) self.assertEqual(0, len(bpy.context.depsgraph.objects))
@@ -35,7 +35,7 @@ class UnitTesting(ViewLayerTesting):
background_scene.objects[0].parent = background_scene.objects[1] background_scene.objects[0].parent = background_scene.objects[1]
# Update depsgraph. # Update depsgraph.
main_scene.update() bpy.context.view_layer.update()
# Test if objects were properly added to depsgraph. # Test if objects were properly added to depsgraph.
self.assertEqual(3, len(bpy.context.depsgraph.objects)) self.assertEqual(3, len(bpy.context.depsgraph.objects))
@@ -50,7 +50,7 @@ class UnitTesting(ViewLayerTesting):
main_scene.background_set = None main_scene.background_set = None
# Update depsgraph. # Update depsgraph.
main_scene.update() bpy.context.view_layer.update()
self.assertEqual(0, len(bpy.context.depsgraph.objects)) self.assertEqual(0, len(bpy.context.depsgraph.objects))

View File

@@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_kid = layer.collections.link(scene_collection_kid) layer_collection_kid = layer.collections.link(scene_collection_kid)
layer_collection_mom.enabled = False layer_collection_mom.enabled = False
bpy.context.scene.update() # update depsgraph bpy.context.view_layer.update() # update depsgraph
cube.select_set(True) cube.select_set(True)
self.assertTrue(cube.visible_get(), "Cube should be visible") self.assertTrue(cube.visible_get(), "Cube should be visible")

View File

@@ -35,13 +35,13 @@ class UnitTesting(ViewLayerTesting):
layer_collection_mom = layer.collections.link(scene_collection_mom) layer_collection_mom = layer.collections.link(scene_collection_mom)
layer_collection_kid = layer.collections.link(scene_collection_kid) layer_collection_kid = layer.collections.link(scene_collection_kid)
bpy.context.scene.update() # update depsgraph bpy.context.view_layer.update() # update depsgraph
cube.select_set(True) cube.select_set(True)
layer_collection_mom.collections[layer_collection_kid.name].enabled = False layer_collection_mom.collections[layer_collection_kid.name].enabled = False
layer_collection_kid.enabled = False layer_collection_kid.enabled = False
bpy.context.scene.update() # update depsgraph bpy.context.view_layer.update() # update depsgraph
self.assertFalse(cube.visible_get(), "Cube should be invisible") self.assertFalse(cube.visible_get(), "Cube should be invisible")
self.assertFalse(cube.select_get(), "Cube should be unselected") self.assertFalse(cube.select_get(), "Cube should be unselected")

View File

@@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_kid = layer.collections.link(scene_collection_kid) layer_collection_kid = layer.collections.link(scene_collection_kid)
layer_collection_mom.enabled = True layer_collection_mom.enabled = True
bpy.context.scene.update() # update depsgraph layer.update() # update depsgraph
cube.select_set(True) cube.select_set(True)
self.assertTrue(cube.visible_get(), "Cube should be visible") self.assertTrue(cube.visible_get(), "Cube should be visible")

View File

@@ -37,12 +37,12 @@ class UnitTesting(ViewLayerTesting):
layer_collection_kid = layer.collections.link(scene_collection_kid) layer_collection_kid = layer.collections.link(scene_collection_kid)
layer_collection_mom.enabled = True layer_collection_mom.enabled = True
bpy.context.scene.update() # update depsgraph bpy.context.view_layer.update() # update depsgraph
cube.select_set(True) cube.select_set(True)
layer_collection_mom.collections[layer_collection_kid.name].selectable = False layer_collection_mom.collections[layer_collection_kid.name].selectable = False
bpy.context.scene.update() # update depsgraph bpy.context.view_layer.update() # update depsgraph
self.assertTrue(cube.visible_get(), "Cube should be visible") self.assertTrue(cube.visible_get(), "Cube should be visible")
self.assertTrue(cube.select_get(), "Cube should be selected") self.assertTrue(cube.select_get(), "Cube should be selected")

View File

@@ -41,7 +41,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_mom.collections[layer_collection_kid.name].selectable = False layer_collection_mom.collections[layer_collection_kid.name].selectable = False
layer_collection_kid.enabled = False layer_collection_kid.enabled = False
bpy.context.scene.update() # update depsgraph layer.update() # update depsgraph
self.assertTrue(cube.visible_get(), "Cube should be visible") self.assertTrue(cube.visible_get(), "Cube should be visible")
self.assertFalse(cube.select_get(), "Cube should be unselected") self.assertFalse(cube.select_get(), "Cube should be unselected")

View File

@@ -23,14 +23,14 @@ class UnitTesting(ViewLayerTesting):
scene_collection = scene.master_collection.collections.new('collection') scene_collection = scene.master_collection.collections.new('collection')
layer_collection = view_layer.collections.link(scene_collection) layer_collection = view_layer.collections.link(scene_collection)
bpy.context.scene.update() # update depsgraph view_layer.update() # update depsgraph
scene_collection.objects.link(cube) scene_collection.objects.link(cube)
self.assertTrue(layer_collection.enabled) self.assertTrue(layer_collection.enabled)
self.assertTrue(layer_collection.selectable) self.assertTrue(layer_collection.selectable)
bpy.context.scene.update() # update depsgraph view_layer.update() # update depsgraph
cube.select_set(True) cube.select_set(True)
self.assertTrue(cube.select_get()) self.assertTrue(cube.select_get())

View File

@@ -40,7 +40,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_mom.enabled = False layer_collection_mom.enabled = False
layer_collection_kid.enabled = True layer_collection_kid.enabled = True
bpy.context.scene.update() # update depsgraph layer.update() # update depsgraph
self.assertTrue(cube.visible_get(), "Object should be visible") self.assertTrue(cube.visible_get(), "Object should be visible")

View File

@@ -40,7 +40,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_mom.collections[layer_collection_kid.name].enabled = False layer_collection_mom.collections[layer_collection_kid.name].enabled = False
layer_collection_kid.enabled = False layer_collection_kid.enabled = False
bpy.context.scene.update() # update depsgraph layer.update() # update depsgraph
self.assertFalse(cube.visible_get(), "Object should be invisible") self.assertFalse(cube.visible_get(), "Object should be invisible")

View File

@@ -40,7 +40,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_mom.collections[layer_collection_kid.name].enabled = False layer_collection_mom.collections[layer_collection_kid.name].enabled = False
layer_collection_kid.enabled = True layer_collection_kid.enabled = True
bpy.context.scene.update() # update depsgraph layer.update() # update depsgraph
self.assertTrue(cube.visible_get(), "Object should be visible") self.assertTrue(cube.visible_get(), "Object should be visible")

View File

@@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_kid = layer.collections.link(scene_collection_kid) layer_collection_kid = layer.collections.link(scene_collection_kid)
layer_collection_mom.enabled = True layer_collection_mom.enabled = True
bpy.context.scene.update() # update depsgraph layer.update() # update depsgraph
self.assertTrue(cube.visible_get(), "Object should be visible") self.assertTrue(cube.visible_get(), "Object should be visible")

View File

@@ -40,7 +40,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_mom.enabled = True layer_collection_mom.enabled = True
layer_collection_kid.enabled = False layer_collection_kid.enabled = False
bpy.context.scene.update() # update depsgraph layer.update() # update depsgraph
self.assertTrue(cube.visible_get(), "Object should be visible") self.assertTrue(cube.visible_get(), "Object should be visible")

View File

@@ -41,7 +41,7 @@ class UnitTesting(ViewLayerTesting):
layer_collection_mom.collections[layer_collection_kid.name].enabled = False layer_collection_mom.collections[layer_collection_kid.name].enabled = False
layer_collection_kid.enabled = False layer_collection_kid.enabled = False
bpy.context.scene.update() # update depsgraph layer.update() # update depsgraph
self.assertTrue(cube.visible_get(), "Object should be visible") self.assertTrue(cube.visible_get(), "Object should be visible")

View File

@@ -39,7 +39,7 @@ class UnitTesting(ViewLayerTesting):
self.assertTrue(layer_collection.enabled) self.assertTrue(layer_collection.enabled)
# Update depsgraph. # Update depsgraph.
scene.update() bpy.context.view_layer.update()
self.assertTrue(ob.visible_get()) self.assertTrue(ob.visible_get())
@@ -47,7 +47,7 @@ class UnitTesting(ViewLayerTesting):
self.assertFalse(layer_collection.enabled) self.assertFalse(layer_collection.enabled)
# Update depsgraph. # Update depsgraph.
scene.update() bpy.context.view_layer.update()
self.assertFalse(ob.visible_get()) self.assertFalse(ob.visible_get())

View File

@@ -34,7 +34,7 @@ class UnitTesting(ViewLayerTesting):
group = layer_collection.create_group() group = layer_collection.create_group()
# update depsgraph # update depsgraph
scene.update() bpy.context.view_layer.update()
# ############################################################ # ############################################################

View File

@@ -41,13 +41,13 @@ class UnitTesting(ViewLayerTesting):
mom_layer_collection.selectable = True mom_layer_collection.selectable = True
# update depsgraph # update depsgraph
scene.update() bpy.context.view_layer.update()
# create group # create group
group = grandma_layer_collection.create_group() group = grandma_layer_collection.create_group()
# update depsgraph # update depsgraph
scene.update() bpy.context.view_layer.update()
# compare # compare
self.assertEqual(len(group.view_layer.collections), 1) self.assertEqual(len(group.view_layer.collections), 1)

View File

@@ -38,13 +38,13 @@ class UnitTesting(ViewLayerTesting):
mom_layer_collection = grandma_layer_collection.collections[mom_scene_collection.name] mom_layer_collection = grandma_layer_collection.collections[mom_scene_collection.name]
# update depsgraph # update depsgraph
scene.update() bpy.context.view_layer.update()
# create group # create group
group = mom_layer_collection.create_group() group = mom_layer_collection.create_group()
# update depsgraph # update depsgraph
scene.update() bpy.context.view_layer.update()
# ############################################################ # ############################################################

View File

@@ -31,14 +31,14 @@ class UnitTesting(ViewLayerTesting):
scene.view_layers.remove(v) scene.view_layers.remove(v)
# update depsgraph # update depsgraph
scene.update() view_layer.update()
# create group # create group
group = bpy.data.groups.new("Switch") group = bpy.data.groups.new("Switch")
group.objects.link(ob) group.objects.link(ob)
# update depsgraph # update depsgraph
scene.update() view_layer.update()
# instance the group # instance the group
empty = bpy.data.objects.new("Empty", None) empty = bpy.data.objects.new("Empty", None)
@@ -57,7 +57,7 @@ class UnitTesting(ViewLayerTesting):
self.assertFalse(empty.select_get()) self.assertFalse(empty.select_get())
# update depsgraph # update depsgraph
scene.update() view_layer.update()
# delete the original object # delete the original object
bpy.ops.object.delete() bpy.ops.object.delete()

View File

@@ -39,7 +39,7 @@ class UnitTesting(ViewLayerTesting):
ob.select_set(True) ob.select_set(True)
# update depsgraph # update depsgraph
scene.update() view_layer.update()
# test itself # test itself
bpy.ops.object.make_single_user(object=True) bpy.ops.object.make_single_user(object=True)

View File

@@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
master_collection.collections.remove(collection_parent) master_collection.collections.remove(collection_parent)
# Update depsgraph. # Update depsgraph.
scene.update() bpy.context.view_layer.update()
# ############################################################ # ############################################################

View File

@@ -63,7 +63,8 @@ class UnitTesting(ViewLayerTesting):
self.assertNotEqual(scene, new_scene) self.assertNotEqual(scene, new_scene)
# update depsgrah # update depsgrah
scene.update() # update depsgraph for view_layer in scene.view_layers:
view_layer.update() # update depsgraph
# compare scenes # compare scenes
for h, layer in enumerate(scene.view_layers): for h, layer in enumerate(scene.view_layers):

View File

@@ -414,7 +414,7 @@ class ViewLayerTesting(unittest.TestCase):
bpy.data.objects.remove(ob, do_unlink=True) bpy.data.objects.remove(ob, do_unlink=True)
elif del_mode == 'OPERATOR': elif del_mode == 'OPERATOR':
bpy.context.scene.update() # update depsgraph bpy.context.view_layer.update() # update depsgraph
bpy.ops.object.select_all(action='DESELECT') bpy.ops.object.select_all(action='DESELECT')
ob.select_set(True) ob.select_set(True)
self.assertTrue(ob.select_get()) self.assertTrue(ob.select_get())
@@ -455,7 +455,7 @@ class ViewLayerTesting(unittest.TestCase):
scene_collection = scene.master_collection.collections.new("Collection") scene_collection = scene.master_collection.collections.new("Collection")
layer.collections.link(scene_collection) layer.collections.link(scene_collection)
bpy.context.scene.update() # update depsgraph bpy.context.view_layer.update() # update depsgraph
self.assertEqual(len(bpy.data.objects), 0) self.assertEqual(len(bpy.data.objects), 0)
@@ -728,7 +728,7 @@ class Clay:
self._object = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh')) self._object = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh'))
# update depsgraph # update depsgraph
self._scene.update() self._layer.update()
scene_collection_grandma = self._scene.master_collection.collections.new("Grandma") scene_collection_grandma = self._scene.master_collection.collections.new("Grandma")
scene_collection_mom = scene_collection_grandma.collections.new("Mom") scene_collection_mom = scene_collection_grandma.collections.new("Mom")
@@ -787,7 +787,6 @@ class Clay:
""" """
ENGINE = 'BLENDER_CLAY' ENGINE = 'BLENDER_CLAY'
self._scene.update() # update depsgraph
self._layer.update() # flush depsgraph evaluation self._layer.update() # flush depsgraph evaluation
# change scene settings # change scene settings