Batch "Load files as as Stack" and name as source folder

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

jeanmi

Batch "Load files as as Stack" and name as source folder

Post by jeanmi »

Hi There - Thanks for reading this post.

Well, I stayed up late late last night trying to work this out... I'm a long time Photoshop user - but new to scripting beyond copying and pasting them from the internet!

I'm surprised that I couldn't find a script for this...

Apologies for wading in as a noob with a request ... Anyone who helps is welcome to have some images retouched for free! web: http://www.theforgeuk.com

---

I would like to automate the "load files as stack" script for multiple folders - and rename the result as the parent folder, and the save in the root folder (i.e. the folder with sub folders in) -

This script does it for the most part, except it uses the statistic script and does some weird overlay - then on top of that merges result to a smart object. I tried and tried to amend this script and make work for load files as stack...
http://ps-scripts.com/bb/viewtopic.php?f=9&t=5507

Other notes:

-I'd love to be able to place in CR2 files as smart objects... so I can adjust exposure a little if needed - currently load files as stack processes files as shot.

-I'd like the file name to remain the same, with or without suffix.

-I'd love the layers to be grouped to a folder named "comp"

- Finally - If you are able to help, is it possible for me to make this a droplet, so I can drop a folder of folders to start the process.


Here's my attempt - adapted from a script to load folders as layers -

This works for the most part except -
I need to point it to each folder, it doesn't load Raw(even if I allow .CR2 as a file type it places in a processed file), it doesn't save to parent folder and doesn't load subfolder name as file name.... hmm, quite a bit - but at least I tried!

Many Thanks!


Code: Select all// Import Folder as Layers - Adobe Photoshop Script
// Description: imports a folder of images as named layers within a new document
// Requirements: Adobe Photoshop CS2, or higher
// Version: 2.0.0, 5/July/2009
// Author: Trevor Morris (trevor@morris-photographics.com)
// Website: http://morris-photographics.com/
// ============================================================================
// Installation:
// 1. Place script in 'C:\Program Files\Adobe\Adobe Photoshop CS#\Presets\Scripts\'
// 2. Restart Photoshop
// 3. Choose File > Scripts > JM MPC
// ============================================================================

// enable double-clicking from Mac Finder or Windows Explorer
// this command only works in Photoshop CS2 and higher


// bring application forward for double-click events
app.bringToFront();

///////////////////////////////////////////////////////////////////////////////
// main - main function
///////////////////////////////////////////////////////////////////////////////
function main() {
   // user settings
   var prefs = new Object();
   prefs.sourceFolder         = '/Volumes/SERVER_RAID/•Current/MPC';  // default browse location (default: '~')
   prefs.removeFileExtensions = false; // remove filename extensions for imported layers (default: true)
   prefs.savePrompt           = true; // display save prompt after import is complete (default: false)
   prefs.closeAfterSave       = true; // close import document after saving (default: false)

   // prompt for source folder
   var sourceFolder = Folder.selectDialog('where the fuck are your files?:', Folder(prefs.sourceFolder));

   // ensure the source folder is valid
   if (!sourceFolder) {
      return;
   }
   else if (!sourceFolder.exists) {
      alert('Source folder not found.', 'Script Stopped', true);
      return;
   }

   // add source folder to user settings
   prefs.sourceFolder = sourceFolder;

   // get a list of files
   var fileArray = getFiles(prefs.sourceFolder);

   // if files were found, proceed with import
   if (fileArray.length) {
      importFolderAsLayers(fileArray, prefs);
   }
   // otherwise, diplay message
   else {
      alert("The selected folder doesn't contain any recognized images.", 'No Files Found', false);
   }
}

///////////////////////////////////////////////////////////////////////////////
// getFiles - get all files within the specified source
///////////////////////////////////////////////////////////////////////////////
function getFiles(sourceFolder) {
   // declare local variables
   var fileArray = new Array();
   var extRE = /\.(?:png|gif|jpg|bmp)$/i;

   // get all files in source folder
   var docs = sourceFolder.getFiles();
   var len = docs.length;
   for (var i = 0; i < len; i++) {
      var doc = docs;

      // only match files (not folders)
      if (doc instanceof File) {
         // store all recognized files into an array
         var docName = doc.name;
         if (docName.match(extRE)) {
            fileArray.push(doc);
         }
      }
   }

   // return file array
   return fileArray;
}

///////////////////////////////////////////////////////////////////////////////
// importFolderAsLayers - imports a folder of images as named layers
///////////////////////////////////////////////////////////////////////////////
function importFolderAsLayers(fileArray, prefs) {
   // create a new document
   var newDoc = documents.add(300, 300, 72, 'Imported Layers', NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1);
   var newLayer = newDoc.activeLayer;
   
   // loop through all files in the source folder
   for (var i = 0; i < fileArray.length; i++) {
      // open document
      var doc = open(fileArray);

      // get document name (and remove file extension)
      var name = doc.name;
      if (prefs.removeFileExtensions) {
         name = name.replace(/(?:\.[^.]*$|$)/, '');
      }

      // convert to RGB; convert to 8-bpc; merge visible
      doc.changeMode(ChangeMode.RGB);
      doc.bitsPerChannel = BitsPerChannelType.EIGHT;
      doc.artLayers.add();
      doc.mergeVisibleLayers();

      // rename layer; duplicate to new document
      var layer = doc.activeLayer;
      layer.name = name;
      layer.duplicate(newDoc, ElementPlacement.PLACEATBEGINNING);

      // close imported document
      doc.close(SaveOptions.DONOTSAVECHANGES);
   }   

   // delete empty layer; reveal and trim to fit all layers
   newLayer.remove();
   newDoc.revealAll();
   newDoc.trim(TrimType.TRANSPARENT, true, true, true, true);

   // save the final document
   if (prefs.savePrompt) {
      // PSD save options
      var saveOptions = new PhotoshopSaveOptions();
      saveOptions.layers = true;
      saveOptions.embedColorProfile = true;

      // prompt for save name and location
      var saveFile = File.saveDialog('something SHORT:');
      if (saveFile) {
         newDoc.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);
      }

      // close import document
      if (prefs.closeAfterSave) {
         newDoc.close(SaveOptions.DONOTSAVECHANGES);
      }
   }
}

///////////////////////////////////////////////////////////////////////////////
// isCorrectVersion - check for Adobe Photoshop CS2 (v9) or higher
///////////////////////////////////////////////////////////////////////////////
function isCorrectVersion() {
   if (parseInt(version, 10) >= 9) {
      return true;
   }
   else {
      alert('This script requires Adobe Photoshop CS2 or higher.', 'Wrong Version', false);
      return false;
   }
}

///////////////////////////////////////////////////////////////////////////////
// showError - display error message if something goes wrong
///////////////////////////////////////////////////////////////////////////////
function showError(err) {
   if (confirm('An unknown error has occurred.\n' +
      'Would you like to see more information?', true, 'Unknown Error')) {
         alert(err + ': on line ' + err.line, 'Script Error', true);
   }
}


// test initial conditions prior to running main function
if (isCorrectVersion()) {
   // remember ruler units; switch to pixels
   var originalRulerUnits = preferences.rulerUnits;
   preferences.rulerUnits = Units.PIXELS;

   try {
      main();
   }
   catch(e) {
      // don't report error on user cancel
      if (e.number != 8007) {
         showError(e);
      }
   }

   // restore original ruler unit
   preferences.rulerUnits = originalRulerUnits;
}

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

jeanmi

Batch "Load files as as Stack" and name as source folder

Post by jeanmi »

bump
CoreyR

Batch "Load files as as Stack" and name as source folder

Post by CoreyR »

Hi,

I'm also having some trouble with a similar situation and would really appreciate some help. Any advice anyone?
CoreyR

Batch "Load files as as Stack" and name as source folder

Post by CoreyR »

Could anyone perhaps help with just the batch loading of stacks? For my needs the naming part isn't as much of an issue, perhaps the OP is ok with that too?

Any help would be really appreciated!!
tstiles

Batch "Load files as as Stack" and name as source folder

Post by tstiles »

This script loads stacked CR2 files as layers and runs a script. It saves the resulting psd on the desktop.

If anyone can help - I would love to know how to change the script so that it loads the files as smart objects.


var stacks = app.document.stacks;
var stackCount = stacks.length;
for(var s = 0;s<stackCount;s++){
var stackFiles = getStackFiles( stacks[s] );
if(stackFiles.length> 1){
var bt = new BridgeTalk;
bt.target = "photoshop";
var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+stackFiles.toSource()+");");
bt.body = myScript;
bt.onResult = function( inBT ) {myReturnValue(inBT.body); }
bt.send(500);
}
}
function getStackFiles( stack ){
var files = new Array();
for( var f = 0; f<stack.thumbnails.length;f++){
files.push(stack.thumbnails[f].spec);
}
return files;
};
function myReturnValue(str){
res = str;
}
function psRemote(stackFiles){
var loadLayersFromScript = true;
var strPresets = localize ("$$$/ApplicationPresetsFolder/Presets=Presets");
var strScripts = localize ("$$$/PSBI/Automate/ImageProcessor/Photoshop/Scripts=Scripts");
var strFile2Stack = "Load Files into Stack.jsx";
var ipFilePath = app.path + "/" + strPresets + "/" + strScripts + "/" + strFile2Stack;
var ipFile = new File (ipFilePath);
$.evalFile( ipFile );
loadLayers.intoStack(stackFiles);
app.doAction (Action1, 'Set1');
var saveFile = new File('~/desktop/'+(new Date().getTime().toString())+'.psd');
app.activeDocument.saveAs(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}