7
$\begingroup$

I am looking for a way to use relative paths in Blender to link to external image, movie, etc... files. I assemble all of my .blend files on my MacBook (OS X Yosemite) and link to the images I've selected by connecting my Finder to a downstairs headless Xubuntu server, through which Blender can then create an absolute path. I then render using this server. However, I have been looking for a way around linking Finder and creating an absolute path, as I must be at my house to connect Finder. I've read that if I use a relative path (//file1), as opposed to an absolute path (Users/.../file1), I should be able to easily send an entire folder, assembled locally on my laptop, to the server, but I haven't been able to get this to work.

In an attempt to create relative paths, I remapped all of the paths in one of my existing .blend files to correspond to the same image textures locally in the folder on my computer where I store said .blend file. I then tried to use the File > External Data > Make All Paths Relative option, but all of my paths were still absolute. Any thoughts?

$\endgroup$

3 Answers 3

1
$\begingroup$

How Relative paths work:

Two of the same file structures

  1. If you are working on COM 2

  2. Your .blend file references paths on COM 2 relatively

  3. If your same structure & content then exists over on COM 1

THEN:

When you copy your updated reference content & .blend from COM 2 over to COM 1, everything should work fine.


If what you are really doing is:

Working on a .blend over on COM 2, using all of your references from COM 1 as something like: //COM1/A/HDPE_Plastic_Texture_001.png

Then relative pathing will not work inherently.

To give you a sense of how you could get it to work, I will demonstrate a few use cases, and it should help you understand what you would need to do in your particular case.


Use Case #1 (The best case):

  1. Your .blend exists at the root of COM 1

SOLUTION:

REPLACE: //COM1/A/HDPE_Plastic_Texture_001.png

WITH: ./A/HDPE_Plastic_Texture_001.png


Use Case #2:

  1. Your .blend exists in a sub-folder of COM 1 - such as //COM1/B/myWorkingFile.blend

SOLUTION:

REPLACE: //COM1/A/HDPE_Plastic_Texture_001.png

WITH: ../A/HDPE_Plastic_Texture_001.png

$\endgroup$
0
$\begingroup$

If you have your blend file in a folder, let's say "my project" and have put all your textures inside the folder "textures" located in "my project" with a hierarchy like this :

my project > test.blend

my project > textures > [texture1].jpg
my project > textures > [texture2].jpg
my project > textures > [texture3].jpg

You can use this script (working in blender 3.6) which will replace all the paths to redirect to your "textures" folder

You can change its name to suit your need, just edit textures_path

import bpy

textures_path = "textures"

def find_nodes_by_type(material, node_type):
    node_list = []
    if material.use_nodes and material.node_tree:
            for n in material.node_tree.nodes:
                if n.type == node_type:
                    node_list.append(n)
    return node_list

material_set = set()

for object in bpy.context.scene.objects:
    for material in object.material_slots:
        image_nodes = find_nodes_by_type(material.material, "TEX_IMAGE")
        if len(image_nodes):
            material_set.add(material)
        
for object in bpy.context.scene.objects:
    for material in object.material_slots:
        if material in material_set:
            print(f"Object {object.name}, uses material {material.name}")
            image_nodes = find_nodes_by_type(material.material, "TEX_IMAGE")    
            for image_node in image_nodes:
                if image_node.image:
                    
                    filename = image_node.image.filepath
                    pos = filename.rfind("\\")
                    filename = filename[pos+1:]
                    
                    print(f"\timage {image_node.image.name} has file '{image_node.image.filepath}'")
                    relative_path = "//" + textures_path + "\\" + filename
                    print(">>",relative_path)
                    bpy.data.images[image_node.image.name].filepath = relative_path
                else:
                    print("\tEmpty image texture")
$\endgroup$
-1
$\begingroup$

the blender file (.blend) and the other files (videos, textures, pictures) should be in the same folder and then "make all paths relative".

$\endgroup$
2
  • 2
    $\begingroup$ This option is not ideal, especially when you are using the same resource libraries over and over again. $\endgroup$
    – Rick Riggs
    Feb 14, 2017 at 20:48
  • $\begingroup$ it worked on linux, interesting some paths were ignored as they are not pointing to files, like the renderto path $\endgroup$ Feb 9, 2019 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .