6
$\begingroup$

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?

$\endgroup$
4
$\begingroup$

Many instructions point to:

bpy.context.view_layer.update()

That's also what's mentioned in API documentation

| improve this answer | |
$\endgroup$
5
$\begingroup$

Dependency graph API changes

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.

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ Replaced bpy.context.scene.update() with dg = bpy.context.evaluated_depsgraph_get() dg.update() works for me, incidently bpy.context.view_layer.update() also gets the job done but I will accept this as the correct answer. $\endgroup$ – Waves May 17 '19 at 17:35
  • $\begingroup$ I can't make much sense out of the python console part in grey. What is the difference between the >>> segments versus those that are not indented? $\endgroup$ – Ben Aug 16 '19 at 16:09
  • 1
    $\begingroup$ >>> 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$ – batFINGER Aug 17 '19 at 9:51
1
$\begingroup$
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.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.