I want to get all textures of all meshes. This how I did it in 2.79:
textures = []
for ob in bpy.data.objects:
if ob.type == "MESH":
for mat_slot in ob.material_slots:
if mat_slot.material:
for tex_slot in mat_slot.material.texture_slots:
textures.append(tex_slot.texture)
up until the line if mat_slot.material: the code will be identical. From there, you’d need to traverse the node tree that is linked to the material, and check for nodes of type TEX_IMAGE there. CAUTION: This won’t include textures that are inside of a node group. Each node group has its own node tree, so you would need to recursively traverse those trees too. Full code below:
import bpy
textures = []
for ob in bpy.data.objects:
if ob.type == "MESH":
for mat_slot in ob.material_slots:
if mat_slot.material:
if mat_slot.material.node_tree:
textures.extend([x for x in mat_slot.material.node_tree.nodes if x.type=='TEX_IMAGE'])
print(textures)