我正在使用 Ubuntu 12.04 上的 Python 脚本更新 Blender 2.63 中的 UV 纹理图像。我可以设置 Image 对象的文件路径属性,但图像没有刷新。我尝试调用 Image 对象的 update() 和 reload() 成员但没有成功。单击 GUI 中的重新加载按钮会按预期刷新图像。将鼠标悬停在 GUI 中的重新加载按钮上表明它使用 bpy.ops.image.reload()。但是当我调用它时,它会返回 CANCELED 状态,我假设是因为有一些方法可以在 bpy.context 模块中选择图像对象,但我一直无法弄清楚如何完成。也许这是一个错误?
相关代码如下:
# Update the filepath of a UV texture image
obj = bpy.context.scene.objects.active
image = obj.data.materials[0].texture_slots[0].texture.image
image.filepath = '//myfile.png'
# None of these work to refresh the image
image.update ()
image.reload ()
bpy.ops.image.reload()