#!BPY """ Name: 'Autosave Render' Blender: 245 Group: 'Wizards' Tooltip: 'Automaticly save every rendered image' """ __author__ = ["macouno"] __url__ = ("http://www.alienhelpdesk.com") __version__ = "1" __bpydoc__ = """\ Autosave Render 1 Use this script as a script link linked to the scene set to execute on render. It uses the directory and filename as found in the ouput dialogue (render buttons). """ # ***** BEGIN GPL LICENSE BLOCK ***** # # Script copyright (C) macouno 2006 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # ***** END GPL LICENCE BLOCK ***** # -------------------------------------------------------------------------- import os import Blender from Blender import Scene, sys from Blender.Scene import Render if Blender.event == "PostRender": # A list of all extensions used in blender imageExtensions = ['.tga','.rgb','.tga','3','.jpg','5','6','7','8','9','10','11','12','13','.tga','.avi','.avi','.png','.avi','19','.bmp','.hdr','.tiff','.exr','24','.tga','.cin','27','.exr','.dds'] # Get the scene and rendering context scn = Scene.GetCurrent() context = scn.getRenderingContext() # Get the render settings renderpath = context.renderPath imagetype = context.imageType extension = imageExtensions[imagetype] # Get the directory and filename dirname = sys.expandpath(sys.dirname(renderpath)) filename = sys.basename(renderpath) # Set default image number imagenr = 1; # See if the directory exists and if so see if an autosave has been done before and what the highest nr was if os.path.exists(dirname): for f in os.listdir(dirname): fname = sys.basename(f) fname, ext= sys.splitext(fname) fparts = fname.split('_') # No need to continue unless the filename matches if len(fparts) > 1 and fparts[0] == filename: fnr = fparts[(len(fparts)-1)] # If a nr was entered that is bigger than the default... add one to that nr and use as new number if fnr and str(fnr).isalnum() and int(fnr) >= imagenr: imagenr = int(fnr) +1 # Make sure the number made is 4 digits long padded with 0's on the left imagenr = str(imagenr).rjust(4, '0') # Make a nice extension including the nr extension = filename + '_' + imagenr + extension # Make as a new path newpath = dirname + sys.sep + extension # Set path. Save the rendered image. Reset path. context.renderPath = newpath; context.saveRenderedImage('', 0) context.renderPath = renderpath print 'Autosaved:', newpath