3

I have a workflow where a set of about 10 textures are generated at different resolutions, these are then collected into folders named e.g. 1000 for the 1000 DPI assets. The texture names follow a strict convention, so the texture 1000/asset_a.png corresponds exactly (other than resolution) to 2000/asset_a.png, for example. These textures are referenced in texture nodes in a material. I'd like to be able to set the texture path base folder for just that material so I can easily switch between different texture sets.

As it stands I have to go into each texture node and manually edit the path to point at the correct folder.

If there was a way to set a path in the scene which I could reference in the texture relative path, that would be ideal, but I can't find any such feature.

Other materials are using textures from the standard texture base folder so I can't just point the file path for textures somewhere else.

Has anyone managed this? Or can anyone suggest a workaround?

Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • 2
    There are two ways: change texture paths using script, or make a node, that switch between two image textures – Crantisz Sep 21 '21 at 14:45
  • 2
    Some other ideas: folder symlinks, using relative paths and moving the .blend file, just renaming the folders before opening the .blend file. – Markus von Broady Sep 21 '21 at 14:52
  • 1
    Another no-coding workaround. Keep all of said materials as a library each in its own individual file, linked from the "main scene" file. You can then go to File > External Data and relocate all said textures to a different folder path. After this step you may even append said material back into the main file, if maintaining multiple libraries is a hassle. – Duarte Farrajota Ramos Sep 21 '21 at 15:53
  • 1
    You can do it with the script in this answer – Marty Fouts Sep 21 '21 at 15:58
  • Some comments for the mod who closed this question: 1 - The linked question involves Python programming which may be out of scope for many 2 - That question is about changing all texture paths, rather than the paths associated with a specific material

    So... yeah, not great, but thanks for closing it for me.

    – Charlie Skilbeck Sep 21 '21 at 22:18
  • @CharlieSkilbeck you can Edit your question and explain why Python solution is invalid. You mentioned in your question declaring a global string, which I think implies strongly a Python solution. – Markus von Broady Sep 22 '21 at 08:39
  • I just meant global as in available to the shader editor even if defined in the scene somehow, perhaps the wording wasn't good - anyway, if it's Python, it's Python, which I really wanted to avoid – Charlie Skilbeck Sep 22 '21 at 09:38

1 Answers1

2

You could use a variation of a script like the one from this answer

import bpy

The path which should be replaced

oldpath = "C:\OLDpath\"

The new path which replaces the old one

newpath = "D:\NewPth\"

image_count = 0

for image in bpy.data.images: if not image.filepath.startswith(oldpath): continue image.filepath = image.filepath.replace(oldpath, newpath) image.reload() image_count += 1

You could add some logic to ask for the two paths so that you don't have to edit the script each time. It might even make a nice add-on.

Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • 1
    fyi I wrote an add-on to do this in a more user friendly way for non Python people. Available here: https://github.com/cskilbeck/bl_TextureLocator – Charlie Skilbeck Sep 28 '21 at 16:07