I'm trying to create a script to pack and save all images when saving the blend file. This is what I have right now:
@persistent def save_data(dummy): #add fake user to images for img in bpy.data.images: img.use_fake_user = True #pack and save the images bpy.ops.file.pack_all() bpy.ops.image.save_dirty() def register(): if not save_data in bpy.app.handlers.save_pre: bpy.app.handlers.save_pre.append(save_data) def unregister(): if save_data in bpy.app.handlers.save_pre: bpy.app.handlers.save_pre.remove(save_data)
The problem with this script is that the images must be saved from memory first for these commands to work (
bpy.ops.image.save_dirty()). There is
bpy.ops.image.pack(as_png=True) command that will pack the images directly from memory but it runs on individual images and it doesn't seem to take effect unless the cursor is inside UV/Image Editor when running it.
Is there a good way to do what I need (pack and save the images directly from memory)? Should I have the script save the files to a temporary location and then pack them?