How do I iterate over all assets in the Asset Browser?

There is no documentation on how to iterate through assets in an asset library.
I tried looking at the python scripts that deal with assets but I can’t quite understand them fully.

I’m trying to iterate over a bunch of materials and generate the previews one by one, because if I let blender do it automatically it fills all 32gb of ram of my system and crashes.

This script loops over any found assets from your asset libraries that are of type object, material and world. You can however easily return any other blend data type by modifying the last lines in the script:

Hello ! I’m honored of having been linked on BSE :slight_smile: Are we talking about assets in the currently opened file or in an user asset library ? If they’re in the current file, you can for example :

idx_start, idx_end = 0, 100 # That's your batch numbers
i = -1
for mat in bpy.data.materials:
    if not mat.asset_data:
        continue
    i += 1
    if i < idx_start:
        continue
    if i >= idx_end:
        break
    mat.asset_generate_preview()

See the docs.

Of course you’ll need to wait long enough for all previews to generate before closing the file otherwise the unfinished previews wil be blank afterwards.