What's the fastest way to change textures for 100 objects?

I had to convert all my PNGs to JPGs, reason why now I need to switch to those new texture files.
Batch converting the image files was easy and fast. But how to do the next step in Blender now?

Thanks in advance guys :slight_smile:

JDL

Open Blender text editor and paste code to it and run script.
Works only if new .jpg files are in the same folders where originals and have same names except file format extension.
Little warning, it will change all images filepaths, not only object image texture filepaths.


import bpy

for i in bpy.data.images:
    i.filepath = i.filepath.replace('.png', '.jpg')

Thanks a million JuhaW :slight_smile:
Parkuhr from Blender.StackExchange suggested a similar solution, also with “import bpy”:
import bpy
for img in bpy.data.images:
img.filepath = img.filepath.replace(’.jpg’, ‘.png’)
img.reload()

What do you think?

Use his, just change ‘.jpg’ and ‘.png’ places if your new formats are .jpg.

Ok, cool.
I must say, I do some HTML/CSS coding, but no idea about Python :frowning:
This being said… where “exactly” I have to enter the path to the images?
And, I suppose I should enter this commands in the Python console in Blender, right?

Repetition is the mother of learning…Post #2 “Open Blender text editor and paste code to it and run script.”
Blender text editor: https://www.youtube.com/watch?v=OzGZ_ssrmsQ

Ok, here’s what I’ve got:

What now?

Attachments



In python, identation means encapsulation…
In this case, the ‘img.filepath…’ should be inside the for ‘for img in …’ loop.

The copy/paste in the python console can sometimes ommit indentations… better write the whole thing.
Instead, you can use the blender’s text editor, create a new text file, and paste the code as you see here:

import bpy
for img in bpy.data.images:
    img.filepath = img.filepath.replace('.png', '.jpg')
    img.reload()

then press the button ‘Run Script’, and it’s done.

You can save the file as a *.py, if later you need to do it again.

1 Like

YES! YES! YES!
it worked!

Thank you so much guys! :slight_smile:
You guys saved me so much work and time :slight_smile:

JDL

1 Like