Batch assign pre existing image files as asset previews

I have a large collection of models that I’d like to batch mark as asset. I use a .bat file to open the .blend and then mark as asset and then save and quit. It works but the issue is the preview. The models I’m trying to mark as asset already have rendered preview images. I just want to assign the corresponding image preview to the asset. This is what I’ve got so far:

import bpy

for obj in
if obj.type == “MESH”:
name = + “.jpg”
dir = “C:\path\” + name


It gives an error of course. The asset marking is working, just need to assign the images as asset previews.

And that error is…

Error relating to this line ‘bpy.ops.ed.lib_id_generate_preview(filepath=dir)’. context is incorrect.

It was solved with the following code:

import bpy

if __name__ == "__main__":
    for obj in
            {"id": obj}, 
1 Like

@minato I am trying to use your script and nothing is happening. Could you please make some video on how to use this the correct way?