|
# A utility proc for saving ALL the images from the "it" window as
# numbered jpeg files. The images are saved in a folder with a
# date and time-stamped name, for example,
# catalog_Tue_Jan__7_21/59/37_2014/
# The location of the directory is determined by the current working
# directory (cwd) of "it". When "it" has been launched by Maya the cwd
# will be the project directory of Maya.
# Useage:
# 1. Open the "it" Console window.
# 2. At the python prompt enter the following command,
# it.extensions.SaveAll()
# or, specify the gamma,
# it.extensions.SaveAll(1.8)
# or, specify the gamma and jpeg quality,
# it.extensions.SaveAll(1.8, 75)
#
# M.Kesson Jan 7 2014
# Edit: Aug 26 2014 Changed default gamma from 2.2 to 1.0
import it, time, os
def SaveAll(gamma=1.0,quality=100):
localtime = time.asctime( time.localtime(time.time()) )
localtime = localtime.replace(' ', '_')
localtime = localtime.replace(':', '_')
outname = 'catalog_%s' % localtime
cwdpath = os.getcwd()
if len(cwdpath) < 3:
it.app.Error('Unable to determine your current working directory.')
it.app.Error('Unable to save the images.')
it.app.RaiseLogWindow()
return
it.app.Info('Saving images to "%s"' % cwdpath)
out_dirpath = os.path.join(cwdpath,outname)
if not os.path.exists(out_dirpath):
os.mkdir(out_dirpath)
aovDict = {}
cat = it.app.GetCurrentCatalog()
img_counter = 1
for i in range (0, cat.GetChildCount()):
img = cat.GetChild(i)
imgname = it.os.path.basename( img.GetFilename() )
if imgname == '_preview':
continue
# Add a padded numeric extension
imgname = imgname + ('.%04d' % img_counter) + '.jpg'
out_imgpath = os.path.join(out_dirpath, imgname)
__saveImage(img, out_imgpath, gamma, quality)
img_counter += 1
# Save any AOV's
for j in range (0, img.GetChildCount()):
aov = img.GetChild(j)
aovname = it.os.path.basename( aov.GetFilename() )
# Remove the extension
aovname = os.path.splitext(aovname)[0]
# Maintain unique counters for each AOV
aov_counter = 1
if aovDict.has_key(aovname):
aov_counter = aovDict[aovname]
aov_counter += 1;
aovDict[aovname] = aov_counter
# Add a padded numeric extension
aovname = aovname + ('.%04d' % aov_counter) + '.jpg'
out_aovpath = os.path.join(out_dirpath, aovname)
__saveImage(aov, out_aovpath, gamma, quality)
#=====================================
# Local private utility procedure
#=====================================
def __saveImage(img,path,gamma,quality):
image = img.GetImage()
image = image.Gamma(gamma);
image.SetMetaDataItem('JPEG_QUALITY', quality)
image.Save(path, ice.constants.FMT_JPEG)
|