# Enumerating Images used by BSDF Node Tree

I'm trying to enumerate and export all images used by all materials in a given .blend project and associating them with named slots / channels used by BSDFs.

My problem is determining which images are assigned to which element in the material's node tree. The toolchain expects things to be named a certain way (ie. "diffuse" instead of "Base Color") and I don't want to always have to remember to change the texture's name every time for every texture. Here's what I've got finding images in Python.

real_texture_list = []
test_texture_list = []

for obj in bpy.context.scene.objects:
for s in obj.material_slots:
if s.material and s.material.use_nodes:
for n in s.material.node_tree.nodes:
if n.type == 'TEX_IMAGE':
if n.image.type == 'UV_TEST':
test_texture_list += [n.image]
elif n.image.type == 'IMAGE':
real_texture_list += [n.image]
elif n.type == 'BSDF_PRINCIPLED':
print(n.inputs["Base Color"]) # want the "Base Color" image object so I can name it something else on export

• Possible duplicate of: python, find images that are used in a node – susu Dec 23 '20 at 23:44
• Not quite sure either. It didn't fully answer my question. I need a list of pairs of (channel, image) per material, where the channel is 'Base Color', 'Normal', etc. The channel list is defined per BSDF type. – Jesse Lactin Dec 24 '20 at 2:40