1
$\begingroup$

I've got a code that loads textures, and determines which is what with eNUM list of texture-type. Basically, I get the right textures connected to their right slots of the material (e.g. 29318291083.TGA goes to Normal). Now what I'm trying to do is rename them and export them out so the texture I just mentioned would come out as 29318291083_Normal.TGA.

I assume Blender isn't able to rename external files so I added a line that packs each texture when it loads it, so I can rename it while packed, then export as a new .TGA.

Now I got the texture's packed but I don't seem to find a way to rename a packed texture.

Any help would be very appreciated. Thanks!

$\endgroup$
1
$\begingroup$

Blender is able to do anything that you can do in python including renaming external files. I don't completely get what you are trying to do in detail, but you can rename textures in blender with

import bpy
bpy.data.textures['29318291083'].name = '29318291083_Normal'

In python you can rename a file with

import os
os.rename('a.txt', 'b.kml')

If your textures are stored similar to .obj and its .mtl (I didn't bother checking tbh) you can just use python to open the file, search for the right lines and rename them. As renaming files and editing text are very common methods, Stackoverflow provides you with lots of help.

$\endgroup$
0
$\begingroup$

Image type texture, is often named from the image filename

For an image type texture the texture has an associated image. bpy.types.Texture.image

>>> D.textures['Texture'].type
'IMAGE'

>>> D.textures['Texture'].image
bpy.data.images['bar.tga']

>>> D.textures['Texture'].image.filepath
'/home/batfinger/foo/bar.tga'

which you can edit. Avoid blender trying to reload from the new path by packing first. Recommend setting a relative filepath (relative to the blend file path).

>>> name = "FooBar"
>>> D.textures['Texture'].image.filepath = f"//bar/{name}.tga"

>>> D.textures['Texture'].name = name

Now when unpacking will be given option to create a Foobar.tga image file in the bar folder of the folder hosting the blend.

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