How to update an object after changing its uv coordinates? I'm creating a node for Sverchok which will apply custom UV map to an object. Pretty simple thing but after applying new UV coordinates to an object object it doesn't update the viewer somehow. Switching to Edit Mode works but I'm sure there is a better way.

The problem can be reproduced this way:


Create a default plane and apply any material with a texture like this: 

then call the code for assigning new UV coordiantes: 


import bpy
obj = bpy.context.active_object
new_uv = [(0.5, 0), (1, 0.5), (0.5, 1), (0, 0.5)]
obj.data.uv_layers['UVMap'].data.foreach_set("uv", [n for v in new_uv for n in v])
print('Done')



However, the changes are only applied when switching to Edit Mode:
This is a simple fix - all you need to do is run the update() function on the object's mesh data: obj.data.update()

Depending on your intended use case, you may also need to run bpy.context.view_layer.depsgraph.update() to update the dependency graph.