For example, I have multiple objects with multiple textures attached to their materials. How to print out for each object in the scene the number of textures it has?
1 Answer
$\begingroup$
$\endgroup$
Here's a script that prints out all objects of type 'MESH'
and the number of textures. It also provides details of the textures and under which material they reside.
import bpy
for obj in bpy.data.objects:
if obj.type != 'MESH':
continue
texture_count = 0
textures = ''
for mat_slot in obj.material_slots:
mat = mat_slot.material
if not mat:
continue
for node in mat.node_tree.nodes:
if node.type.startswith('TEX_'):
textures += '\t' + mat_slot.name + ": " + node.type + " (linked=" + str(any(link.is_linked for link in node.outputs)) + ')\n'
texture_count += 1
print(f"{obj.name} ===> {texture_count}")
print(f"{textures}")
Example Output: