Rename all textures on model


#1

Hi. How can I rename all the textures on my model? (ex. image_1; image_2…) I did that with a script if I remember well… But I don’t remember that. Someone knows the solution? Thanks!


#2

First collect all of the models materials:

mats=Sketchup.active_model.materials

Now step through and rename them thus:

rename="image_001"
mats.each{|mat| mat.name=rename; rename.next! }

However, if you mean the actual image files associated with a texture which is attached to a material, then it’s more convoluted, you need to filter the materials for those with textures, then save the texture file renamed [JPG or PNG] to some folder [perhaps in TEMP or with the model ?], and then immediately reassign that renamed file with the texture…

dir=Sketchup.temp_dir # or perhaps =Sketchup.active_model.path.dirname
rename="image_001"
Sketchup.active_model.materials.find_all{|m| m.texture }.each{|material|
  extname=File.extname(material.texture.filename)
  # keep file type, or perhaps =".png"
  puts basename=rename+extname
  rename.next! # increment rename by one digit
  filename=File.join(dir, basename)
  material.texture.write(filename)
  material.texture=filename
}
puts

This sorts the model’s textured materials files in the order they were added to the model.


#3

Thank a lot. I meant the first option


#5

Thanks for the tips TIG !


#6

TIG thanks a alot for this tip. But it is erasing the materials UVs. So is it possible to keep the same UV data and collect the textures with new name in a folder?