3
$\begingroup$

Let's say I have a very complex Blender project with a lot of external data, such as images, geometry cache files, VDB sequences, text scripts, and maybe something else I don't even know about. How can I get a list of filepaths to all of the external data files loaded to the project? For several internal reasons I have to avoid using pack/unpack external data option. I know there are such operators as bpy.ops.file.make_paths_absolute() which somehow iterate through paths and make them absolute or relative, but those are not Python operators, so I can not read their code. I tried to search in bpy.path, but could not find anything helpful.

$\endgroup$

1 Answer 1

3
$\begingroup$

Find all library data-block

import bpy

cls = type(bpy.data.objects)

for attr in dir(bpy.data):
    collections = getattr(bpy.data, attr)
    if isinstance(collections, cls):
        for data_block in collections:
            if hasattr(data_block, "library") and data_block.library:
                print(f'[{data_block.__class__}] {data_block.name} :  {data_block.library.filepath}')

Find Images filepath

import bpy
from bpy.types import Image

cls = type(bpy.data.objects)

for attr in dir(bpy.data):
    collections = getattr(bpy.data, attr)
    if isinstance(collections, cls):
        for data_block in collections:
            if hasattr(data_block, "library") and data_block.library:
                print(f'[{data_block.__class__}] {data_block.name} :  {data_block.library.filepath}')

            if isinstance(data_block, Image):
                print(f'Image :  {data_block.filepath}')

This should be what you want

import bpy

cls = type(bpy.data.objects)

for attr in dir(bpy.data):
    collections = getattr(bpy.data, attr)
    if isinstance(collections, cls):
        for data_block in collections:
            if hasattr(data_block, "library") and data_block.library:
                print(f'Data-Block Library [{data_block.__class__}] {data_block.name} :  {data_block.library.filepath}')

            if hasattr(data_block, "filepath") and data_block.filepath:
                print(f'[{data_block.__class__}] :  {data_block.filepath}')
$\endgroup$
1
  • $\begingroup$ Thank you! It seems it finds all paths. Some minor addjustments are needed to convert relative paths into absolute ones. Especially those starting with "//..\\..\\..\\" because Blender bpy.path.abspath() doesn't replace this syntax with actual parent folders. But this can be easily done either with pathlib module or by running bpy.ops.file.make_paths_absolute() before the code you provided. As far as these conditions were not written in the question, your code totally corresponds to the question. $\endgroup$ Commented Mar 24 at 7:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .