Skip to main content
deleted 126 characters in body
Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

You can load the contents with bpy.data.libraries.load and the argument assets_only=True to filter only assets. Thanks to viktor for pointing it out.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = filepaths.asset_libraries

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()]
    print(f"Checking the content of library '{library_name}' :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file), assets_only=True) as (file_contents, _):
            # Note this will print out the names of the objects,
            # Not the actual objects
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.

Unfortunately this answer will also print out the names of items in the asset library directories even if they have not been marked as assets. One could list all the assets in the library but that would mean having to open all files to check their contents which might be very heavy in terms of computations for big libraries.

As far as I know there is currently no straightforward way to get a list of all assets in an asset library with the python API.

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = filepaths.asset_libraries

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()]
    print(f"Checking the content of library {library_name} :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file)) as (file_contents, _):
            # Note this will print out the names of the objects,
            # Not the actual objects
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.

Unfortunately this answer will also print out the names of items in the asset library directories even if they have not been marked as assets. One could list all the assets in the library but that would mean having to open all files to check their contents which might be very heavy in terms of computations for big libraries.

As far as I know there is currently no straightforward way to get a list of all assets in an asset library with the python API.

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

You can load the contents with bpy.data.libraries.load and the argument assets_only=True to filter only assets. Thanks to viktor for pointing it out.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = filepaths.asset_libraries

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()]
    print(f"Checking the content of library '{library_name}' :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file), assets_only=True) as (file_contents, _):
            # Note this will print out the names of the objects,
            # Not the actual objects
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.
deleted 6 characters in body
Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = prefs.filepaths.asset_libraries

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()]
    print(f"Checking the content of library {library_name} :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file)) as (file_contents, _):
            # Note this will print out the names of the objects,
            # Not the actual objects
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.

Unfortunately this answer will also print out the names of items in the asset library directories even if they have not been marked as assets. One could list all the assets in the library but that would mean having to open all files to check their contents which might be very heavy in terms of computations for big libraries.

As far as I know there is currently no straightforward way to get a list of all assets in an asset library with the python API.

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = prefs.filepaths.asset_libraries

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()]
    print(f"Checking the content of library {library_name} :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file)) as (file_contents, _):
            # Note this will print out the names of the objects,
            # Not the actual objects
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.

Unfortunately this answer will also print out the names of items in the asset library directories even if they have not been marked as assets. One could list all the assets in the library but that would mean having to open all files to check their contents which might be very heavy in terms of computations for big libraries.

As far as I know there is currently no straightforward way to get a list of all assets in an asset library with the python API.

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = filepaths.asset_libraries

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()]
    print(f"Checking the content of library {library_name} :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file)) as (file_contents, _):
            # Note this will print out the names of the objects,
            # Not the actual objects
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.

Unfortunately this answer will also print out the names of items in the asset library directories even if they have not been marked as assets. One could list all the assets in the library but that would mean having to open all files to check their contents which might be very heavy in terms of computations for big libraries.

As far as I know there is currently no straightforward way to get a list of all assets in an asset library with the python API.

added 569 characters in body
Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = prefs.filepaths.asset_libraries

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()]
    print(f"Checking the content of library {library_name} :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file)) as (file_contents, _):
            # Note this will print out the names of the objects,
            # Not the actual objects
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.

Unfortunately this answer will also print out the names of items in the asset library directories even if they have not been marked as assets. One could list all the assets in the library but that would mean having to open all files to check their contents which might be very heavy in terms of computations for big libraries.

As far as I know there is currently no straightforward way to get a list of all assets in an asset library with the python API.

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = prefs.filepaths.asset_libraries

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()]
    print(f"Checking the content of library {library_name} :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file)) as (file_contents, _):
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.

The asset libraries are stored in the preferences filepaths. Preferences are accessed with the current context.

An User Asset Library object holds the name of the library and the path to its root directory.

import bpy
from pathlib import Path

prefs = bpy.context.preferences
filepaths = prefs.filepaths
asset_libraries = prefs.filepaths.asset_libraries

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()]
    print(f"Checking the content of library {library_name} :")
    for blend_file in blend_files:
        with bpy.data.libraries.load(str(blend_file)) as (file_contents, _):
            # Note this will print out the names of the objects,
            # Not the actual objects
            print(file_contents.objects)
            print(file_contents.materials)
            print(file_contents.worlds)
            # etc.

Unfortunately this answer will also print out the names of items in the asset library directories even if they have not been marked as assets. One could list all the assets in the library but that would mean having to open all files to check their contents which might be very heavy in terms of computations for big libraries.

As far as I know there is currently no straightforward way to get a list of all assets in an asset library with the python API.

Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106
Loading