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:
parent
1d2e4c44bd
commit
33e8db94b1
|
@ -102,16 +102,16 @@ To avoid expensive recalculations every time a property is modified,
|
|||
Blender defers making the actual calculations until they are needed.
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
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?
|
||||
|
|
|
@ -160,7 +160,8 @@ class BPyOpsSubModOp:
|
|||
else:
|
||||
import bpy
|
||||
for scene in bpy.data.scenes:
|
||||
scene.update()
|
||||
for view_layer in scene.view_layers:
|
||||
view_layer.update()
|
||||
|
||||
__doc__ = property(_get_doc)
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ def example_function(text, save_path, render_path):
|
|||
scene.collection.objects.link(light_ob)
|
||||
light_ob.location = 2.0, 2.0, 5.0
|
||||
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
if save_path:
|
||||
bpy.ops.wm.save_as_mainfile(filepath=save_path)
|
||||
|
|
|
@ -25,7 +25,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
bpy.context.window.scene = main_scene
|
||||
|
||||
# Update depsgraph.
|
||||
main_scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
# Safety check, there should be no objects in thew newly created scene.
|
||||
self.assertEqual(0, len(bpy.context.depsgraph.objects))
|
||||
|
@ -35,7 +35,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
background_scene.objects[0].parent = background_scene.objects[1]
|
||||
|
||||
# Update depsgraph.
|
||||
main_scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
# Test if objects were properly added to depsgraph.
|
||||
self.assertEqual(3, len(bpy.context.depsgraph.objects))
|
||||
|
@ -50,7 +50,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
main_scene.background_set = None
|
||||
|
||||
# Update depsgraph.
|
||||
main_scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
self.assertEqual(0, len(bpy.context.depsgraph.objects))
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_kid = layer.collections.link(scene_collection_kid)
|
||||
|
||||
layer_collection_mom.enabled = False
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
bpy.context.view_layer.update() # update depsgraph
|
||||
cube.select_set(True)
|
||||
|
||||
self.assertTrue(cube.visible_get(), "Cube should be visible")
|
||||
|
|
|
@ -35,13 +35,13 @@ class UnitTesting(ViewLayerTesting):
|
|||
|
||||
layer_collection_mom = layer.collections.link(scene_collection_mom)
|
||||
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)
|
||||
|
||||
layer_collection_mom.collections[layer_collection_kid.name].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.select_get(), "Cube should be unselected")
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_kid = layer.collections.link(scene_collection_kid)
|
||||
|
||||
layer_collection_mom.enabled = True
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
layer.update() # update depsgraph
|
||||
cube.select_set(True)
|
||||
|
||||
self.assertTrue(cube.visible_get(), "Cube should be visible")
|
||||
|
|
|
@ -37,12 +37,12 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_kid = layer.collections.link(scene_collection_kid)
|
||||
|
||||
layer_collection_mom.enabled = True
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
bpy.context.view_layer.update() # update depsgraph
|
||||
|
||||
cube.select_set(True)
|
||||
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.select_get(), "Cube should be selected")
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_mom.collections[layer_collection_kid.name].selectable = 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.assertFalse(cube.select_get(), "Cube should be unselected")
|
||||
|
||||
|
|
|
@ -23,14 +23,14 @@ class UnitTesting(ViewLayerTesting):
|
|||
scene_collection = scene.master_collection.collections.new('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)
|
||||
|
||||
self.assertTrue(layer_collection.enabled)
|
||||
self.assertTrue(layer_collection.selectable)
|
||||
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
view_layer.update() # update depsgraph
|
||||
cube.select_set(True)
|
||||
self.assertTrue(cube.select_get())
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_mom.enabled = False
|
||||
layer_collection_kid.enabled = True
|
||||
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
layer.update() # update depsgraph
|
||||
self.assertTrue(cube.visible_get(), "Object should be visible")
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_mom.collections[layer_collection_kid.name].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")
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_mom.collections[layer_collection_kid.name].enabled = False
|
||||
layer_collection_kid.enabled = True
|
||||
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
layer.update() # update depsgraph
|
||||
self.assertTrue(cube.visible_get(), "Object should be visible")
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_kid = layer.collections.link(scene_collection_kid)
|
||||
|
||||
layer_collection_mom.enabled = True
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
layer.update() # update depsgraph
|
||||
self.assertTrue(cube.visible_get(), "Object should be visible")
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_mom.enabled = True
|
||||
layer_collection_kid.enabled = False
|
||||
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
layer.update() # update depsgraph
|
||||
self.assertTrue(cube.visible_get(), "Object should be visible")
|
||||
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
layer_collection_mom.collections[layer_collection_kid.name].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")
|
||||
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
self.assertTrue(layer_collection.enabled)
|
||||
|
||||
# Update depsgraph.
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
self.assertTrue(ob.visible_get())
|
||||
|
||||
|
@ -47,7 +47,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
self.assertFalse(layer_collection.enabled)
|
||||
|
||||
# Update depsgraph.
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
self.assertFalse(ob.visible_get())
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
group = layer_collection.create_group()
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
|
||||
# ############################################################
|
||||
|
|
|
@ -41,13 +41,13 @@ class UnitTesting(ViewLayerTesting):
|
|||
mom_layer_collection.selectable = True
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
# create group
|
||||
group = grandma_layer_collection.create_group()
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
# compare
|
||||
self.assertEqual(len(group.view_layer.collections), 1)
|
||||
|
|
|
@ -38,13 +38,13 @@ class UnitTesting(ViewLayerTesting):
|
|||
mom_layer_collection = grandma_layer_collection.collections[mom_scene_collection.name]
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
# create group
|
||||
group = mom_layer_collection.create_group()
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
|
||||
# ############################################################
|
||||
|
|
|
@ -31,14 +31,14 @@ class UnitTesting(ViewLayerTesting):
|
|||
scene.view_layers.remove(v)
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
view_layer.update()
|
||||
|
||||
# create group
|
||||
group = bpy.data.groups.new("Switch")
|
||||
group.objects.link(ob)
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
view_layer.update()
|
||||
|
||||
# instance the group
|
||||
empty = bpy.data.objects.new("Empty", None)
|
||||
|
@ -57,7 +57,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
self.assertFalse(empty.select_get())
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
view_layer.update()
|
||||
|
||||
# delete the original object
|
||||
bpy.ops.object.delete()
|
||||
|
|
|
@ -39,7 +39,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
ob.select_set(True)
|
||||
|
||||
# update depsgraph
|
||||
scene.update()
|
||||
view_layer.update()
|
||||
|
||||
# test itself
|
||||
bpy.ops.object.make_single_user(object=True)
|
||||
|
|
|
@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
|
|||
master_collection.collections.remove(collection_parent)
|
||||
|
||||
# Update depsgraph.
|
||||
scene.update()
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
|
||||
# ############################################################
|
||||
|
|
|
@ -63,7 +63,8 @@ class UnitTesting(ViewLayerTesting):
|
|||
self.assertNotEqual(scene, new_scene)
|
||||
|
||||
# update depsgrah
|
||||
scene.update() # update depsgraph
|
||||
for view_layer in scene.view_layers:
|
||||
view_layer.update() # update depsgraph
|
||||
|
||||
# compare scenes
|
||||
for h, layer in enumerate(scene.view_layers):
|
||||
|
|
|
@ -414,7 +414,7 @@ class ViewLayerTesting(unittest.TestCase):
|
|||
bpy.data.objects.remove(ob, do_unlink=True)
|
||||
|
||||
elif del_mode == 'OPERATOR':
|
||||
bpy.context.scene.update() # update depsgraph
|
||||
bpy.context.view_layer.update() # update depsgraph
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
ob.select_set(True)
|
||||
self.assertTrue(ob.select_get())
|
||||
|
@ -455,7 +455,7 @@ class ViewLayerTesting(unittest.TestCase):
|
|||
scene_collection = scene.master_collection.collections.new("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)
|
||||
|
||||
|
@ -728,7 +728,7 @@ class Clay:
|
|||
self._object = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh'))
|
||||
|
||||
# update depsgraph
|
||||
self._scene.update()
|
||||
self._layer.update()
|
||||
|
||||
scene_collection_grandma = self._scene.master_collection.collections.new("Grandma")
|
||||
scene_collection_mom = scene_collection_grandma.collections.new("Mom")
|
||||
|
@ -787,7 +787,6 @@ class Clay:
|
|||
"""
|
||||
ENGINE = 'BLENDER_CLAY'
|
||||
|
||||
self._scene.update() # update depsgraph
|
||||
self._layer.update() # flush depsgraph evaluation
|
||||
|
||||
# change scene settings
|
||||
|
|
Loading…
Reference in New Issue