Skip to main content
added 24 characters in body
Source Link
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
# all materials that have the
for samem namein asbpy.data.materials:
 a UVTex
materials = [(m,img = bpy.data.images.get(m.name.replace("_dds", ".dds"))) for m in bpy.data.materials]
     
for m, img in materials:
    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
     bsdf = nodes.get('Diffuse BSDF')
    if bsdf:
        #link to bsdf
        m.node_tree.links.new(bsdf.inputs['Color'], 
                teximage.outputs['Color'])

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
# all materials that have the same name as a UVTex
materials = [(m, bpy.data.images.get(m.name.replace("_dds", ".dds"))) for m in bpy.data.materials]
     
for m, img in materials:
    if not img:
        continue
    if m.use_nodes:
        # done this already??
        continue
    m.use_nodes = True

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

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'])
Source Link
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
# all materials that have the same name as a UVTex
materials = [(m, bpy.data.images.get(m.name.replace("_dds", ".dds"))) for m in bpy.data.materials]
     
for m, img in materials:
    if not img:
        continue
    if m.use_nodes:
        # done this already??
        continue
    m.use_nodes = True

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