11
$\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$
  • 1
    $\begingroup$ I guess you could write a script that saves image and then saves the blend file... $\endgroup$ – cegaton Jun 22 '14 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$ – GiantCowFilms Jun 22 '14 at 17:58
  • 1
    $\begingroup$ Theres a patch to do just this: developer.blender.org/D398 $\endgroup$ – ideasman42 Jun 23 '14 at 5:51
  • $\begingroup$ @ideasman42 does that mean I have to build it myself? Is the patch going it release? $\endgroup$ – GiantCowFilms Jun 23 '14 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 Jun 25 '14 at 4:35
9
$\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$
  • $\begingroup$ > You can easily turn it into and addon. How is that done? $\endgroup$ – GiantCowFilms Sep 12 '14 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 Sep 12 '14 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 Apr 4 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.