Hello,
I imported a model in 3DS format.
I noticed in the uv editor, when selecting model faces, that images are like myimage.bmp.001, myimage.bmp.002, etc… on different objects instead of myimage.bmp for all objects using the same image.
I’m trying to write a script to fix this.
However, when using bpy.data.images.load, the file name is also suffixed by a number. If the last file was, for example, myimage.bmp.234, when using the load instruction, the file name becomes myimage.bmp.235 (and it increased for each face!) instead of myimage.bmp.
Thanks in advance for your help.
import bpy
import os
from bpy.props import StringProperty
model_directory = os.path.dirname(bpy.data.filepath)
#for obj in bpy.context.scene.objects:
for obj in bpy.context.selected_objects:
if obj.type == "MESH":
for fuv_num, fuv in enumerate(obj.data.uv_textures):
for f in fuv.data:
if f.image is not None:
print(" >>> ", f.image.name)
str_index = f.image.name.find('BMP.')
if str_index != -1:
new_image_name = f.image.name[:str_index+3] # Remove .XXX after .BMP
new_file_name = model_directory + '\\' + new_image_name
img = bpy.data.images.load(filepath=new_file_name)
f.image = img
print(f.image.name, new_image_name)