There was a script that you wrote for me

`import bpy import os import shutil

Initialize an empty set to store unique file paths

file_paths = set()

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 set file_path = node.image.filepath file_paths.add(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 set file_path = scene.library.filepath file_paths.add(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 set file_path = cache_file.filepath file_paths.add(file_path)

Get the blend file's directory

blend_dir = os.path.dirname(bpy.data.filepath)

Create the assets folder in the blend file's directory

assets_dir = os.path.join(blend_dir, "assets") os.makedirs(assets_dir, exist_ok=True)

Copy each file in file_paths to the assets folder

num_files = 0 for file_path in file_paths: # Get the real file path file_path = os.path.realpath(bpy.path.abspath(file_path))

# Check if the file exists
if not os.path.exists(file_path):
    print("File", file_path, "does not exist. Skipping...")
    continue

# Get the destination file path
dest_path = os.path.join(assets_dir, os.path.basename(file_path))

# Try to copy the file
try:
    shutil.copy2(file_path, dest_path)
    num_files += 1
except PermissionError as e:
    print("Failed to copy file", file_path, "due to permission error. Skipping...")
    continue

Print the report to the console

print("Copied", num_files, "files from the following locations:") for file_path in file_paths: print("-", file_path)`

This script is used to collect all of the external assets used in a Blender project and copy them to an "assets" folder in the project directory. The assets are collected from textures used in materials, linked libraries, and Alembic cache files. The script initializes an empty set, file_paths, to store the unique file paths of the assets. The script then loops through all objects in the scene, checking for materials and textures, and adds the file path of any textures it finds to file_paths. The script also loops through all scenes in the blend file, checking for linked libraries, and adds the file path of any linked libraries it finds to file_paths. The script also loops through all Alembic cache files and adds the file path of any cache files it finds to file_paths. The script then creates an "assets" folder in the project directory, and copies all of the assets in file_paths to that folder. If a file cannot be copied due to a permission error, the script will print an error message to the console and skip that file. The script then prints a report to the console that lists the number of files copied and their locations.

Let's modify it. After copying all files this script must replace the old file paths in all scanned blender entities with new file paths, located in the "assets" folder. And please reduce the amount of comments in the script

Here's the modified version of the script with fewer comments:

import bpy
import os
import shutil

file_paths = set()

for obj in bpy.data.objects:
    if obj.material_slots:
        for material_slot in obj.material_slots:
            if material_slot.material.node_tree:
                for node in material_slot.material.node_tree.nodes:
                    if node.type == "TEX_IMAGE" and node.image:
                        file_path = node.image.filepath
                        file_paths.add(file_path)

for scene in bpy.data.scenes:
    if scene.library:
        file_path = scene.library.filepath
        file_paths.add(file_path)

for cache_file in bpy.data.cache_files:
    file_path = cache_file.filepath
    file_paths.add(file_path)

blend_dir = os.path.dirname(bpy.data.filepath)
assets_dir = os.path.join(blend_dir, "assets")
os.makedirs(assets_dir, exist_ok=True)

num_files = 0
for file_path in file_paths:
    file_path = os.path.realpath(bpy.path.abspath(file_path))
    if not os.path.exists(file_path):
        print("File", file_path, "does not exist. Skipping...")
        continue
    dest_path = os.path.join(assets_dir, os.path.basename(file_path))
    try:
        shutil.copy2(file_path, dest_path)
        num_files += 1
    except PermissionError as e:
        print("Failed to copy file", file_path, "due to permission error. Skipping...")
        continue

print("Copied", num_files, "files from the following locations:")
for file_path in file_paths:
    print("-", file_path)

for obj in bpy.data.objects:
    if obj.material_slots:
        for material_slot in obj.material_slots:
            if material_slot.material.node_tree:
                for node in material_slot.material.node_tree.nodes:
                    if node.type == "TEX_IMAGE" and node.image:
                        old_path = node.image.filepath
                        node.image.filepath = os.path.join(assets_dir, os.path.basename(old_path))

for scene in bpy.data.scenes:
    if scene.library:
        old_path = scene.library.filepath
        scene.library.filepath = os.path.join(assets_dir, os.path.basename(old_path))

for cache_file in bpy.data.cache_files:
    old_path = cache_file.filepath
    cache_file.filepath = os.path.join(assets_dir, os.path.basename(old_path))

linked_files_collect_addon_05.py