serializing PSD export

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

cece

serializing PSD export

Post by cece »

Hi everyone I need some urgent help, if possible
I have one single PSD document from where I have separate 260 different areas and save them as single jpgs.
I can pretty much cover all the steps with actions but when I come up to "saving" I have the problem that PS4 saves them all with the same name, as it uses the name of the original document...is there any trick or any script I could use to solve that. Otherwise it will lake days doing that work...

Thanks in advance!

Christine
Mike Hale

serializing PSD export

Post by Mike Hale »

It's hard to say if a script can be added to your action to do the saving. It's very likely that it can be.
Does your action save each section as it selects/creates it or does is save all the parts at the end of the action?
cece

serializing PSD export

Post by cece »

Hi Mike,

the action saves each section at the time, so in between I can select the new section and run the action again...
Mike Hale

serializing PSD export

Post by Mike Hale »

This may or may not work with your action. It assumes that the first document open is the source document and gets the folder and name from that document. It then looks in that folder for files with that document name and a number suffix. If it doesn't find one it saves the active document with the source document's name and a suffix of '_001'. If it finds files that already have a suffix it saves using the source doc's name and increments the number. Note that it only has a crude error check.

Code: Select all// This script will save the active document to a folder with an incremental sufix
// Change the options below to match your needs
try{
   var saveFolder = app.documents[0].path;
   var saveExt = 'psd';
   var saveSufixStart = '_';
   var saveSufixLength = 3;

   // End of user options
   //==========================================
   function zeroPad ( num, digit ){
      var tmp = num.toString();
      while (tmp.length < digit) { tmp = "0" + tmp;}
      return tmp;
   }
   var docName = decodeURI ( app.documents[0].name );
   docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];
   var saveName = docName[ 1 ]; // activeDocument name with out ext
   var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix

   if( files.length == 0 ) {  // no file with that name so start at one
      var saveNumber = 1;
   }
   if( files.length == 1 ) { // one file found, see if it has a sufix
      var fileName = decodeURI ( files[ 0 ].name );
      fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];
      if( fileName[1].match( /_(\d{3})$/ ) == null ){
        var saveNumber = 1;// does not have sufix so set to one
      } else{// has sufix
        var saveNumber = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1
      }
   }
   if( files.length > 1 ){
      files.sort();
      var fileName = decodeURI ( files[ files.length -1 ].name );
      fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];
      var saveNumber = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1
   }
   var saveFile = new File( saveFolder + '/' + saveName + saveSufixStart + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );
   activeDocument.saveAs( saveFile, undefined ,true ,Extension.LOWERCASE);
}catch(e){
   alert('Script error\rFile not saved');
}
cece

serializing PSD export

Post by cece »

Hi Mike,

this works GREAT!!! Thank you sooooo much!!!!!
I actually need to safe that "optimized for the web" resized in 70px x 40px (not proportionally)...
Is that possible to adjust on the script? Otherwise I will have to run through all the stuff twice?

Really you already made my day!
Thanks
cece

serializing PSD export

Post by cece »

sorry to bother....there is a problem with the script:
it stops saving file after the numeratio 008 (and i need it to go till 90).
can someone look into that....pleaaaaaaase
cece

serializing PSD export

Post by cece »

...it is actually saving...but always as 001 so it looks like h jumbs back to 001 after 008...
xbytor

serializing PSD export

Post by xbytor »

Try changing 'parseInt' to 'Number' where it appears in the script.
cece

serializing PSD export

Post by cece »

great that works.
THANKS!!!
Mike Hale

serializing PSD export

Post by Mike Hale »

I am glad that you have it working but the script I posted does not use Number. It already uses parseInt.