13
$\begingroup$

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!

$\endgroup$
5
  • 1
    $\begingroup$ I guess you could write a script that saves image and then saves the blend file... $\endgroup$
    – user1853
    Commented Jun 22, 2014 at 17:56
  • $\begingroup$ 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. $\endgroup$ Commented Jun 22, 2014 at 17:58
  • 1
    $\begingroup$ Theres a patch to do just this: developer.blender.org/D398 $\endgroup$
    – ideasman42
    Commented Jun 23, 2014 at 5:51
  • $\begingroup$ @ideasman42 does that mean I have to build it myself? Is the patch going it release? $\endgroup$ Commented Jun 23, 2014 at 15:00
  • 2
    $\begingroup$ @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. $\endgroup$
    – ideasman42
    Commented Jun 25, 2014 at 4:35

1 Answer 1

11
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ > You can easily turn it into and addon. How is that done? $\endgroup$ Commented Sep 12, 2014 at 20:23
  • $\begingroup$ It's covered here: blender.org/documentation/blender_python_api_2_71_release/…, but I did that for you (see my updated answer) $\endgroup$
    – CodeManX
    Commented Sep 12, 2014 at 20:37
  • $\begingroup$ 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 $\endgroup$
    – Mr Zak
    Commented Apr 4, 2019 at 14:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .