I'm writing a script to export assets with custom previews. The script works perfectly for objects, but collections show no previews. The preview data appears to be missing in collection assets.
Blender Version: 4.3.2
Problem Description:
- When exporting objects (e.g. Cube), the preview image is properly embedded
- When exporting collections, the .preview data seems missing despite setting it through API
Object (Cube) Preview Data Exists in .blend File - Data API Browser View
Collection Preview Data Missing in .blend File
Code Sample:
import array
from PIL import Image
import bpy
from bpy import types
preview_image_path = "D:/Temp/test_prview_img.png"
preview_resize = (128, 128)
collection_name = "Collection"
export_collection_path = "D:/Temp/test_collection_asset.blend"
object_name = "Cube"
export_object_path = "D:/Temp/test_cube_asset.blend"
collection = bpy.data.collections.get(collection_name)
object = collection.objects.get(object_name)
def write_asset(obj: types.Object, export_path):
obj.asset_mark()
preview = obj.preview_ensure()
image = Image.open(preview_image_path)
image = image.transpose(Image.FLIP_TOP_BOTTOM)
image = image.convert("RGBA").convert("RGBa")
image = image.resize(preview_resize)
image_data = array.array("i", image.tobytes())
preview.image_size = preview_resize
preview.image_pixels = image_data
data_blocks = set()
data_blocks.add(obj)
bpy.data.libraries.write(export_path, data_blocks, compress=True)
obj.asset_clear()
write_asset(collection, export_collection_path)
write_asset(object, export_object_path)
Question:
Is there special handling required for collection asset previews? Why does the same code work for objects but not collections? Are there additional steps to persist collection preview data through bpy.data.libraries.write?

