Skip to main content
Inspiring
July 22, 2011
Answered

Would like to automate open stacks as layers + run action. Possible with script??

  • July 22, 2011
  • 7 replies
  • 18664 views

I would like to automate part of my workflow that involves opening stacked images as layers in Ps CS5 and running an PS action that composites the layers and processes the image. Something similar to 'Process Collection' in Bridge CS5 only with my own action instead of merge to HDR/Panorama.

Apparently this is possible with Mac 'Automator' - is there anything I can do in Windows? I don't have any experience with writing scripts, but have friends that can help. Can someone tell me if its possible and point me in the right direction please?

This topic has been closed for replies.
Correct answer Michael_L_Hale

That's very true, maybe something on the line of:

var saveFile = new File('~/desktop/'+(new Date().getTime().toString())+'.psd');


I was also wondering about the action, as it is now it it only run once, but does it need to be run on each layer?


For the name, I was thinking more along the lines of using the name of the first image in the stack( or top layer name ) as part of the filename.

For the action, I think it depends on the action and how the script is to be used. My tests had images stacks of three images each. The action selects the top layer, inverts, selects the layer below, inverts, selects the layer below and inverts. So it inverts all the layers because it expects there to be three layers. I guess you could script running the action on all the layers but depending on the workflow that might not be ideal.

7 replies

RocketStudios
Participating Frequently
July 24, 2015

Hi Everyone,

I have the same issue as Orchid Photo- I have hundreds of folders, each with 5 images in them- I need each set of 5 to be aligned then stacked as layers. I have tried the scripts kindly presented here, however I can't seem to get them to run (I have never run a script before). When I run, it says "Result:onSelect()" and the "Stack to Layers" appears in the tool menu, but nothing happens at all when I click it. Even if I highlight a folder, or the set of 5 images I want stacked and click "Stack to Layers", nothing happens.

What could I be doing wrong here? I appreciate any help I could get.

Also, just for clarification, I am assuming that this script will open multiple folders as different stacks in photoshop? Ultimately I want to save a single stacked 5 layer image (non-flattened) in its state of alignment, as a tiff in the original folder. (RGB, NIR and Red Edge bands of light).

Just for context, I am aligning slightly offsetting satellite images covering the same areas. Each folder has a frame (5 bands) that I'd like to realign so the surface features match perfectly over the 5 bands/frame.  

Complicated eh? But any help would be immensely appreciated. Donations are available.

JJMack
Community Expert
Community Expert
July 24, 2015

It is not clear what you have done what script your tried. I can guess you tried from the bridge something in the tool menu,  Like  menu Tools>Photoshop>Load Files into Photoshop Layers.... I would not expect scripts  to open different folder if your using the bridge for I do not think selecting folders would be allowed.  I would expect Photoshop to start, run the script and the script to open the file you select thumbnails for in the bridge and create a stack of layer in a new document.

Supply pertinent information for quicker answers

The more information you supply about your situation, the better equipped other community members will be to answer. Consider including the following in your question:

  • Adobe product and version number
  • Operating system and version number
  • The full text of any error message(s)
  • What you were doing when the problem occurred
  • Screenshots of the problem
  • Computer hardware, such as CPU; GPU; amount of RAM; etc.



JJMack
RocketStudios
Participating Frequently
July 24, 2015

Hi JJMack, Thanks a lot for your response. Really appreciate it.

I did this from bridge--I tried almost all of the script variations shared here- the scripts add a command at the bottom of the tool menu- in my case I tried two scripts and you can see double of the same command on the bottom of the tool menu (see my pics).

Not really sure what I am doing wrong here because yes photoshop I imagined would open automatically- but nothing happens at all- not even an error message when I click "Stack to Layers".

As for my info:

Adobe CS6 version 13.0

Bridge CS6,5.0.0.399x64

Windows 8,

Alienware 18, 32gb ram, gtx780, 3gb vid memory...

Inspiring
April 15, 2012

I found a wierd bug in bridge/photoshop while using this script. Or is there something missing from the script?

I discovered that if I change just one raw file in camera raw (eg WB) then the 'load files into stack' script loads all the files with default settings, ignoring the changes made and saved while in Camera RAW.

On the otherhand if I change all the files, then the camera raw settings are observed and the files are loaded into a stack with the new settings.

The problem only seems to happen when the discussed script sends the files from bridge for processing. It doesn't happen if I manually go to BRIDGE >Tools>Photoshop>Loadfiles into Photoshop Layers.

Does anyone know if there is a fix? The script is below

var stacks = app.document.stacks;
var stackCount = stacks.length;
for(var s = 0;s<stackCount;s++){
      var stackFiles = getStackFiles( stacks );
      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.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);
}

Inspiring
July 25, 2011

Thank you Michael, Paul and JJMack. This has given me plenty to work with!! 

Inspiring
July 24, 2011

I have moved this thread to Bridge Scripting. Please see http://forums.adobe.com/thread/881342 for further discussion.

Inspiring
July 24, 2011

Just to see if this can be scripted in javascript I created this quick and dirty Bridge script. It will process all image stacks in the open window of Bridge and save the psd to the desktop.

// this is a Bridge script, run from ESTK with Bridge as the target app

var stacks = app.document.stacks;
var stackCount = stacks.length;
for(var s = 0;s<stackCount;s++){
     var stackFiles = getStackFiles( stacks );
     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.spec);
     }
     return files;
};
function myReturnValue(str){
     res = str;
}
// don't have comments in the psRemote function
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 ('Action 2', 'test');
     var saveFile = new File('~/desktop/'+app.activeDocument.name+'.psd');
     app.activeDocument.saveAs(saveFile);
     app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

I am sure that the members of the Bridge Scripting forum can come up with something better but this does work for me with CS5.

JJMack, you can also create a image stack in Bridge by selecting a group of images then from the context menu choose Stack-Group as Stack.

Inspiring
August 11, 2011

Paul is right, you need to edit the doAction line. You can also remove the line  $.evalFile( ipFile );

toSource() removes line breaks and other formatting chars like tabs and extra spaces. Because the line breaks are removed line comments ( comments that start with // ) have the effect of commenting out the remainder of the function thus breaking the script. But because the toSource step in done in the Bridgetalk message it is not obvious. The line about comments was just a reminder not to use line comments.


Thanks again Paul and Michael. I had the script running really well yesterday morning and saved it without making any changes. However, this morning it has stopped working completely. Something is stopping the send to photoshop bit as I can't get the stacks to open at all. The only thing that I can think that has changed was an automatic windows update.

The script is below - would you mind checking it for me? Is there something I'm missing?

I'm running it in Extend Toolkit set to Bridge CS5 Main Engine.


var stacks = app.document.stacks;
var stackCount = stacks.length;
for(var s = 0;s<stackCount;s++){
var stackFiles = getStackFiles( stacks );
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.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);
loadLayers.intoStack(stackFiles);
app.doAction ('hdr3', 'timsactions');
var saveFile = new File('~/desktop/'+(new Date().getTime().toString())+'.psd');
app.activeDocument.saveAs(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

Inspiring
July 23, 2011

Thanks for your help. I should clarify that I would like to automatically process multiple stacks. So a script would need to..

1) find first stack

2) open as layers

3) run PS action

4) save and close (as psd preserving layers)

5) find next stack, etc

I'm already using open as layers (LR3) and processing with the PS action. While this semi automatic approach is ok, the actions take a while to work through and it would better if I was free to do something else  (such as help my wife with our newborn).

JJMack
Community Expert
Community Expert
July 23, 2011

I do not use LR so I'm having a bit of a problem understanding where these stacks are created or are coming from.  You wrote something about LR open as layers. Since LR is not a image editor that supports layers LR must be passing a collection or an image list to Photoshop to have Photoshop load the images into a document as layers in its layers stack. Any way this sounds like how you create a stack so you can process it with your action.  So I don't understand what you mean by find next stack.  As far as I know LR does not have scripting support.  So I don't understand how your stack  processing can work in LR where you loop through stacks and process them with a Photoshop Action.  I know LR can use Photoshop but I know little about LR output module and its features can it loop through collections of images and have Photoshop stack them into layers and run an action or a script?   Describing your stack concept in more detail here may help.

JJMack
Inspiring
July 23, 2011

I'm managing my workflow with Lightroom 3 at the moment. In Lightroom I can automatically stack images (by capture time). I then manually select two or three images and open as layers in Photoshop CS5. Then run my ps processing action, save and close and move on to the next stack. Lightroom doesn't support layers however you can send the files to Photoshop as layers (same as Bridge) and reimport the file as a layered psd doc.

Just ignore the LR comment though, because as you said, it doesn't support script. If a script is possible, then I would use Bridge to do the job - ie stack images and open the stacks as layers in Photoshop.

Bridge CS5 has the Batch or Image Processor tools that open images, run actions, save and close etc. This is what I need - only with the ability to recognise Stacks and open the Stacks as layers documents.

Inspiring
July 22, 2011

Stilesy911 wrote:

Something similar to 'Process Collection' in Bridge CS5 only with my own action instead of merge to HDR/Panorama.

If you want to work from Bridge you can select your images then choose Tools-Photoshop-Load Files into Photoshop Layers. That will load the selected files into one Photoshop document. You can then run your action.

It may be possible to automate your entire workflow but we would need more details about what you want done.

JJMack
Community Expert
Community Expert
July 22, 2011

Photoshop CS5 ships with a Script "Load Files into  Stack" that uses three of Photoshop Stacks Scripts that will load files into a Document as layers and optionally align them. In this forum or PS-Scripting community web other have written scripts to load  files into a stack and align them as a strip by expanding the canvas and then moving the newly add layer into the expanded area.  Auto Collection I believe is what you wrote about seems to be listed the Bridge  preferences in startup scripts.

"Load files into a stack" is not a plug in script so you can not record its use in an action and bypass its dialog. However you may be able to do what you want in two stages. "Load Files into stack"  followed by a script that you write that will process all the layers. Targeting layer after layer and do your action for each targeted layer.

JJMack