Replace duplicate textures with exisiting one in Python I have two objects with different shaders on it, but with the same texture piped in.
I need to replace the texture with the .006 with the original one by code.
How do I do that?

It supposed to look like this, you see that they share the same texture because of the small 2 next to the textfield.

My code so far:
import bpy

for material in bpy.data.materials:
    if material.node_tree:
        for x in material.node_tree.nodes:
            if x.type == 'TEX_IMAGE':
                xSplit = x.image.name.split('.')
                imageName = xSplit[0]
                if xSplit[-1].isdigit():
                    originalName = xSplit[0] + '.' + xSplit[1]
                    print(originalName)
                    #This does not work:
                    x.image.name = 'static_deckchair_plastic_BaseColor.jpg'
Try this
import bpy, re

def get_original_name(name):
    &quot;&quot;&quot;When name looks like 'X.001', return 'X'. Otherwise None.&quot;&quot;&quot;
    i = name.rfind('.')
    if i != -1:
        suf = name[i+1:]
        if len(suf) == 3 and suf.isdigit():
            return name[:i]
    return None

for material in bpy.data.materials:
    if material.node_tree is None:
        continue
    for node in material.node_tree.nodes:
        if node.type != 'TEX_IMAGE':
            continue
        if node.image is None:
            continue
        original_name = get_original_name(node.image.name)
        if original_name is None:
            continue
        if original_name in bpy.data.images:
            node.image = bpy.data.images[original_name]