2
$\begingroup$

I am trying to build a tool to bake textures from one UV layout to another via scripting but before baking all the textures must be loaded in blender.

I set the filepath to my image:

bpy.data.images["Image"].filepath = "/Users/John/image.jpg"

In texture panel I can see the source is set, but Can't Load Image is displayed

bpy.data.images["Image"].reload()

seems to have no effect. Only after manually clicking the reload button, the texture is refreshed. Any ideas how to reload the texture through Python, also I'm trying to run this headlessly if it matters.

Thanks!

.reload() function not working

$\endgroup$
  • $\begingroup$ Same issue, but appears only if an image was missed first, blender 2.78. Move / resize panels do not help. $\endgroup$ – peko Jul 11 '18 at 8:06
2
$\begingroup$

Hi in addition to what J. Bakker said, here is some code that I used in TexTools addon to reload all images and remove unused ones.

import bpy

# Clean up unused images
for img in bpy.data.images:
    if not img.users:
        bpy.data.images.remove(img)

#Reload all File images
for img in bpy.data.images :
    if img.source == 'FILE' :
        img.reload()

Hope this helps,

renderhjs

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

The image is reloaded. the display is not updated. If you move/resize the panel, you will see that the image is updated.

Best to do that by using tag_redraw on the correct area.

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