It seems the following is no longer available in blender 2.8 api
bpy.context.scene.update()
How do we update objects in the scene that have been changed by the script now?
Many instructions point to:
bpy.context.view_layer.update()
That's also what's mentioned in API documentation
Main goal here is to make it obvious and predictable about what is going on.
Summary of changes.
Access to dependency graph is now only possible to a fully evaluated graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph, and also making explicit that getting update dependency graph is not
cheap.Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.If datablock is not covered by dependency graph it will be returned as-is.
Similarly, request for original from an ID which is not evaluated will return ID as-is.
Removed scene.update().
This is very expensive to update all the view layers.
Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
Some fiddling in python console.
>>> dg = C.evaluated_depsgraph_get(
evaluated_depsgraph_get()
Context.evaluated_depsgraph_get()
Get the dependency graph for the current scene and view layer,
to access to data-blocks with animation and modifiers applied.
If any data-blocks have been edited, the dependency graph will be updated.
This invalidates all references to evaluated data-blocks from the dependency graph.
>>> dg = C.evaluated_depsgraph_get()
>>> ob = C.object
>>> ob.evaluated_get(
evaluated_get()
Object.evaluated_get(depsgraph)
Get corresponding evaluated ID from the given dependency graph
>>> ob.evaluated_get(dg)
bpy.data.objects['Cube']
>>> dg.update(
update()
Depsgraph.update()
Re-evaluate any modified data-blocks, for example for animation or modifiers.
This invalidates all references to evaluated data-blocks from this dependency graph.
>>> dg.update()
This is all pretty new and TBH haven't tested it against how the old scene update was used. Speculating, it appears can evaluate changes to a single object based on the depsgraph, without the need to expensively update scene and all objects in it.
>>>
is the console prompt, anything after I've typed in. If ends with say (
I've hit autocomplete and pasted that. Go to the console and have a fiddle.
$\endgroup$
Commented
Aug 17, 2019 at 9:51
bpy.context.view_layer.update()
works but as mentioned here : corner cases in blender
This method can also help in removing these corner cases but use every time you toggle the property.
I experimented with it, it remove the bug of rendering the object while I set the obj.hide_render = True.
wrestled with this till I was ready to tear out my hair. here's a hacky catchall to force an update when all the other solutions fail.
for obj in bpy.context.scene.objects:
obj.hide_render = obj.hide_render