can you write me the simpliest blender python script that collets all external file paths to the array?

Here's a simple Python script that collects all external file paths used in the current Blender scene and adds them to a list:

import bpy

# Initialize an empty list to store file paths
file_paths = []

# Iterate over all objects in the scene
for obj in bpy.data.objects:
    # Check if the object has a material
    if obj.material_slots:
        # Iterate over all materials assigned to the object
        for material in obj.material_slots:
            # Check if the material uses a texture
            if material.material.texture_slots:
                # Iterate over all textures used by the material
                for texture_slot in material.material.texture_slots:
                    # Check if the texture uses an image
                    if texture_slot and texture_slot.texture.image:
                        # Get the file path of the image and add it to the list
                        file_path = texture_slot.texture.image.filepath
                        file_paths.append(file_path)

# Print the list of file paths
print(file_paths)

can you add also linked blender scene files and linked alembic files check?

Sure! Here's an updated version of the script that also collects external file paths for linked Blender scenes and Alembic files:

import bpy

# Initialize an empty list to store file paths
file_paths = []

# Iterate over all objects in the scene
for obj in bpy.data.objects:
    # Check if the object has a material
    if obj.material_slots:
        # Iterate over all materials assigned to the object
        for material in obj.material_slots:
            # Check if the material uses a texture
            if material.material.texture_slots:
                # Iterate over all textures used by the material
                for texture_slot in material.material.texture_slots:
                    # Check if the texture uses an image
                    if texture_slot and texture_slot.texture.image:
                        # Get the file path of the image and add it to the list
                        file_path = texture_slot.texture.image.filepath
                        file_paths.append(file_path)

# Iterate over all scenes in the blend file
for scene in bpy.data.scenes:
    # Check if the scene has a linked library
    if scene.library:
        # Get the file path of the linked library and add it to the list
        file_path = scene.library.filepath
        file_paths.append(file_path)

# Iterate over all Alembic cache files in the blend file
for cache_file in bpy.data.cache_files:
    # Get the file path of the Alembic cache file and add it to the list
    file_path = cache_file.filepath
    file_paths.append(file_path)

# Print the list of file paths
print(file_paths)

AttributeError: 'Material' object has no attribute 'texture_slots’

It seems the texture_slots attribute doesn't exist on a Material object in the version of Blender you are using. Here's an updated version of the script that works around this issue:

import bpy

# Initialize an empty list to store file paths
file_paths = []

# Iterate over all objects in the scene
for obj in bpy.data.objects:
    # Check if the object has a material
    if obj.material_slots:
        # Iterate over all materials assigned to the object
        for material_slot in obj.material_slots:
            # Check if the material uses a texture
            for texture_slot in material_slot.material.texture_slots:
                # Check if the texture uses an image
                if texture_slot and texture_slot.texture.image:
                    # Get the file path of the image and add it to the list
                    file_path = texture_slot.texture.image.filepath
                    file_paths.append(file_path)

# Iterate over all scenes in the blend file
for scene in bpy.data.scenes:
    # Check if the scene has a linked library
    if scene.library:
        # Get the file path of the linked library and add it to the list
        file_path = scene.library.filepath
        file_paths.append(file_path)

# Iterate over all Alembic cache files in the blend file
for cache_file in bpy.data.cache_files:
    # Get the file path of the Alembic cache file and add it to the list
    file_path = cache_file.filepath
    file_paths.append(file_path)

# Print the list of file paths
print(file_paths)

same error

In this case, you can access the textures used by a material through the material.node_tree.nodes["Image Texture"].image property. Here's an updated version of the script:

import bpy

# Initialize an empty list to store file paths
file_paths = []

# Iterate over all objects in the scene
for obj in bpy.data.objects:
    # Check if the object has a material
    if obj.material_slots:
        # Iterate over all materials assigned to the object
        for material_slot in obj.material_slots:
            # Check if the material uses a texture
            for node in material_slot.material.node_tree.nodes:
                if node.type == "TEX_IMAGE" and node.image:
                    # Get the file path of the image and add it to the list
                    file_path = node.image.filepath
                    file_paths.append(file_path)

# Iterate over all scenes in the blend file
for scene in bpy.data.scenes:
    # Check if the scene has a linked library
    if scene.library:
        # Get the file path of the linked library and add it to the list
        file_path = scene.library.filepath
        file_paths.append(file_path)

# Iterate over all Alembic cache files in the blend file
for cache_file in bpy.data.cache_files:
    # Get the file path of the Alembic cache file and add it to the list
    file_path = cache_file.filepath
    file_paths.append(file_path)

# Print the list of file paths
print(file_paths)

AttributeError: 'NoneType' object has no attribute 'nodes'

This error occurs because the nodes attribute of the material's node tree is only present if the material uses a shader node setup. To avoid the error, you can check if the material's node tree exists before accessing its nodes:

import bpy

# Initialize an empty list to store file paths
file_paths = []

# Iterate over all objects in the scene
for obj in bpy.data.objects:
    # Check if the object has a material
    if obj.material_slots:
        # Iterate over all materials assigned to the object
        for material_slot in obj.material_slots:
            # Check if the material has a node tree
            if material_slot.material.node_tree:
                # Check if the material uses a texture
                for node in material_slot.material.node_tree.nodes:
                    if node.type == "TEX_IMAGE" and node.image:
                        # Get the file path of the image and add it to the list
                        file_path = node.image.filepath
                        file_paths.append(file_path)

# Iterate over all scenes in the blend file
for scene in bpy.data.scenes:
    # Check if the scene has a linked library
    if scene.library:
        # Get the file path of the linked library and add it to the list
        file_path = scene.library.filepath
        file_paths.append(file_path)

# Iterate over all Alembic cache files in the blend file
for cache_file in bpy.data.cache_files:
    # Get the file path of the Alembic cache file and add it to the list
    file_path = cache_file.filepath
    file_paths.append(file_path)

# Print the list of file paths
print(file_paths)

cool, that works

I'm glad to hear that! If you have any further questions or need help with anything else, don't hesitate to ask!

linked_files_collect_addon_01.py