1
$\begingroup$

Hello I am currently trying to get collection names of blend files in a specific file without opening them. However I cannot find any resources around this topic. How can I achieve this?

What needs to be obtained:

[folder]

  • blend1
    • collection1 <--
    • collection2 <--
    • collection3 <--
  • blend2
    • collection1 <--
    • collection2 <--
    • collection3 <--
  • blend3
    • collection1 <--
    • collection2 <--
    • collection3 <--
$\endgroup$

1 Answer 1

2
$\begingroup$

You could use the low-level API for reading the collection data block from each blend file.

import bpy
import os

# "//" identifier for the current blend file
folder = bpy.path.abspath("//")

# get all blend files in the folder
blends = [f for f in os.listdir(folder) if f.endswith(".blend")]

for blend in blends:
    blend_path = os.path.join(folder, blend)
    # load the data from the file and print all collections
    with bpy.data.libraries.load(blend_path) as (data_from, _):
        # file name, list of collections
        print (blend, [c for c in data_from.collections])

Output:

b1.blend ['Collection1', 'Collection2']
b2.blend ['Collection2', 'Collection3']
b3.blend ['Collection4', 'Collection5']
$\endgroup$
1
  • $\begingroup$ This works as I needed it to be thank you so much! $\endgroup$
    – KripC2160
    Commented Feb 12, 2022 at 9:35

You must log in to answer this question.

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