I have a giant asset browser with over 2000 items. Some of the items have tags (product numbers), but not many. I would now like to output all the names of the items and their stored tags so that I can then enter all the entries in Excel, find the matching product numbers manually and then maintain the asset library and add product numbers as tags. I already have a script that outputs all names and writes them to a text file. However, this must now be extended to get and include the stored tags.
import bpy
from pathlib import Path
output_file_path = Path("/tmp/asset_library_contents.txt")
prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = filepaths.asset_libraries
with output_file_path.open("w") as output_file:
for asset_library in asset_libraries:
library_name = asset_library.name
library_path = Path(asset_library.path)
blend_files = [fp for fp in library_path.glob("**/*.blend") if fp.is_file()]
output_file.write(f"Checking the content of library '{library_name}' :\n")
for blend_file in blend_files:
with bpy.data.libraries.load(str(blend_file), assets_only=True) as (file_contents, _):
output_file.write(f"File: {blend_file.name}\n")
output_file.write("Objects:\n")
for obj in file_contents.objects:
output_file.write(f" - {obj}\n")
output_file.write("Collections:\n")
for col in file_contents.collections:
output_file.write(f" - {col}\n")
output_file.write("\n")
```