BL25: force matrix_world to reflect change in location, scale, or rotation? [SOLVED]

I see that if I programmatically change an object’s location attribute, then that object’s matrix_world is not updated until after the script returns and then is called again. Is there a way to get matrix_world to immediately reflect a programmatic change to the object’s location, scale, or rotation attributes? I want to avoid having to do the matrix operations in my code for various reasons (one of which is that I’d rather rely on Blender updating any other things that might need updating of which I may not be aware–even in future releases.).

For example, the following shows that it is not updated. (I used no references because I’d heard of a related bug in some versions of Blender)


bpy.context.scene.objects["Cube"].location[0]=11
print(bpy.context.scene.objects["Cube"].matrix_world)

Run that code once and you’ll see the previous X value, run it again to see the updated value.

try using scene.update()

import bpy
bpy.context.scene.objects["Cube"].location[0]=11
bpy.context.scene.update()
print(bpy.context.scene.objects["Cube"].matrix_world)

is that what you needed…?

That was exactly what I needed. Thanks!