Skip to main content
2 of 2
added 24 characters in body
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Script.

Similarly to How can I connect a texture node to a material with Python? the script below, Looks for all materials whose name has a corresponding image (note the ugly check for "_dds" to ".dds") Then for all material, image pairs adds an image texture node and connects it to the BSDF node.

Script assumes you have already loaded in the images, a simple process of multiple selecting images when opening.

import bpy
     
for m in bpy.data.materials:
    img = bpy.data.images.get(m.name.replace("_dds", ".dds"))
    if not img:
        continue
    if m.use_nodes:
        # done this already??
        continue
    m.use_nodes = True

    nodes = m.node_tree.nodes
    bsdf = nodes.get('Diffuse BSDF')
    if bsdf:
        # add image texture
        teximage = nodes.new('ShaderNodeTexImage')
        teximage.image = img            
        #link to bsdf
        m.node_tree.links.new(bsdf.inputs['Color'], 
                teximage.outputs['Color'])
batFINGER
  • 85.2k
  • 10
  • 114
  • 244