Auto save images along with .blend

Blender has a very irritating quirk in which it fails to save an image that you have painted on, when the .blend is saved. To fix this you have to remember to use "save as image", before you save the .blend. Is there anyway to automatically save the image when saving the .blend?

P.S.

A script free solution(or a script that runs whenever I save, no matter which button/keyboard short cut.)would be of great value!

• I guess you could write a script that saves image and then saves the blend file... – user1853 Jun 22 '14 at 17:56
• I was hoping for a script free solution, since I would have to remember to fire the script instead of the regular save function, which defeats the point. – GiantCowFilms Jun 22 '14 at 17:58
• Theres a patch to do just this: developer.blender.org/D398 – ideasman42 Jun 23 '14 at 5:51
• @ideasman42 does that mean I have to build it myself? Is the patch going it release? – GiantCowFilms Jun 23 '14 at 15:00
• @GiantCowFilms - not sure yet, the patch is more a test-case, even though it works OK. I'm not really happy with just adding more options. – ideasman42 Jun 25 '14 at 4:35

This sample code will save external images before saving to .blend (overwrites the originals):

bl_info = {
"name": "Auto-save external images",
"author": "CoDEmanX",
"version": (1, 0),
"blender": (2, 67, 0),
"location": "",
"description": "Save image datablocks on saving .blend",
"warning": "Works on external images only!",
"wiki_url": "",
"category": "System"}

import bpy

def save_external_images(dummy):
for img in bpy.data.images:
img.save()

def register():
bpy.app.handlers.save_pre.append(save_external_images)

def unregister():
bpy.app.handlers.save_pre.remove(save_external_images)

if __name__ == "__main__":
register()


Make sure you enable this addon by default!

It does not work on internal image datablocks, unless you extent above code to save to an external file or maybe pack internally.

• > You can easily turn it into and addon. How is that done? – GiantCowFilms Sep 12 '14 at 20:23
• It's covered here: blender.org/documentation/blender_python_api_2_71_release/…, but I did that for you (see my updated answer) – CodeManX Sep 12 '14 at 20:37
• For some reason the script doesn't work as it is written above and gives error "RenderResult has no image data to be saved" or something like that. I suppose it tries to save Render Result as well when iterating through images. When I tried to make checking with "if img.is_dirty" inside the loop to iterate only through images with Asterisk it worked. It would be great to edit the code or append it so to make it working out of the box – Mr Zak Apr 4 '19 at 14:07