How to add an Image Texture to multiple Material Index?

I have 500+ materials that need the same Image Texture copied into each. I can create the new image texture in Mat-00001, then copy and paste it into Mat-00002, and so on, but how can I add that Image Texture to all Mat-xxxxx at once? Thanks for any info. Using 4.1

You’re going to need to write a Python script to do this

1 Like

I did a smaller test with 50 Mats, as the end result was for custom puzzles for the VR 3d puzzle game Puzzling Places, but the processing failed, as I suspected it might with the mesh build. So, for now, this is a moot point for me, but in the event others need it in the future, any Python script or other solutions are quite welcome.

This really doesn’t sound like a thing you should want to do. Why exactly do you need this? Why not make one shader that has different properties per object or in specific circumstances? Sounds like an XY problem. What’s the original goal? What’s the context?

Scene comprising of 50 meshes. Each mesh has a material. 50 Meshes are Joined into a single mesh, then Merged by Distance. Pack Islands for new single mesh. 50 materials need to become a single material. Create new UV Map for the single mesh. Add Image Texture to a Mat Index. Copy that Image Texture to every Mat Index. Bake the 50 image materials to 1 image. Apply new image to single mesh using new UV map.

Yeah. Well this still sounds like something you should not want to do. What’s the reason for doing this? Why not use a single material for all those 50 objects in the first place?

1 Like

I tend to agree.

Sounds a little convoluted. Unless I’m missing something, you’re better off just doing everything needed within a single shader, as Martin says. But since you asked, you can employ groups to share things across materials.

1 Like

“Why not use a single material for all those 50 objects in the first place?” I don’t know, nor do I care. My position in the pipeline is to take the scene that comes my way and make it a single mesh and single material. I am capable of doing it, and was simply looking to see if there was a way with Blender to copy and paste a single image texture to multiple mats at once.

Hello this “simple” addon took me at least a long waiting time between propmt iterations and fixing bugs with the help of DeepSeek, and mainly because that f*cking “the server is busy, please try later” message popping dozens of times…

Usage: Select one or multiple objects, if multiple select last to make active the object containing the image texture in its material slot, open shader editor and select the nodes you want to copy/paste to the other materials (it will copy either an image texture if selected, or you can select along with that for example the texture coordinate and mapping node as well in the shader editor) and the image will be connected automatically to the principled bsdf or diffuse bsdf nodes base color inputs only.

test it and tell me if is working as expected, i only tested it in blender 4.3.2

Copy_Image_Texture_To_All_Materials.py (6.1 KB)

1 Like

It seems it makes your work harder, so you might have a reason to care. That caring about what you are doing might save you some headaches.

If you have a valid reason for this, you can use Python, sure. This will take materials of all selected objects. You have to have an image loaded to your scene. Replace “MyImage.jpg” with whatever image name you have. Note that it does not necessarily has to be the file name - image block can have any name.

import bpy

#get all unique materials
materials = set() 
for o in bpy.context.selected_objects:
    materials.update(o.data.materials)
    
for mat in materials:
    tree = mat.node_tree
    nodes = tree.nodes
    im_node = nodes.new("ShaderNodeTexImage")
    #add an existing image previously loaded to the scene
    im_node.image = bpy.data.images["MyImage.jpg"]
    #set the location of the node
    im_node.location = (-500,300)
    #Conect it to whatever you want
    if "Principled BSDF" in nodes: #might not be the best idea to search by name
        princ = nodes["Principled BSDF"]
        tree.links.new(im_node.outputs['Color'], princ.inputs['Base Color'])

You might wan to perform other checks if for example the image texture already exists and is connected.

I always search for this list of material node names in bpy when adding material nodes with Python. Might be useful.

2 Likes

The work here is fantastic, thanks, I will test as soon as possible. Prior to, I want to clarify that I do not want the Image Texture connecting to anything. What I do is select a Mat, add an Image Texture. Make a New image, 8192x8192, call it Single Material. I do not connect it to anything. I then want to copy and paste that unconnected blank Image Texture called Single Material into every Mat. That is all I want to do.

That new unconnected blank Image Texture in every Mat is what all the Mats will bake to. Once they are all baked to the Image Texture called Single Material, I will save the image, delete all the Mats and the original UV map. I will then create a new Mat and select the new UV Map also created earlier, I will connect that Single Material image to the single mesh.

1 Like