There seems to be limited documentation on how to access the Asset Browser
via Python, but I found that you can access the asset_data
property (of type bpy.types.AssetMetaData
) on objects and materials to get information about their location in the Asset Browser. Here's a simple script that iterates over all the materials contained within the catalog named "Color Library" in the Asset Browser and assigns each material one at a time to the selected object and does a render. The rendered images will be named render_(material-name).png and be stored in the path specified by the directory
variable.
import bpy
import os
directory = r'/path/to/render_directory/' #example: r'C:\Users\xxxx\Desktop'
scene = bpy.context.scene
o = bpy.context.object
def render(image_name):
#scene.frame_current = 1
#scene.frame_set(1)
scene.render.filepath = os.path.join(directory, f'{image_name}')
scene.render.image_settings.file_format = 'PNG'
print("rendering file:", scene.render.filepath)
bpy.ops.render.render(animation=False, write_still=True)
def iterate_asset_browser_and_render():
for m in bpy.data.materials:
data = m.asset_data
if not data or not data.catalog_simple_name.startswith('Color Library'):
continue
if not o.material_slots:
o.data.materials.append(None)
o.data.materials[0] = m
render(f"render_{m.name}.png")
iterate_asset_browser_and_render()