1
$\begingroup$

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: enter image description here

  • 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: enter image description here
$\endgroup$
1
$\begingroup$

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.

|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.