23 Replies Latest reply on Jan 30, 2014 12:16 PM by zephyrandy

    Automate merge files into stack

    jmug45 Level 1

      Hi all,

       

      I need to find a way to do the following:

       

      Merge 4 currently open images into a single stack into separate layers.

      Screen all layers

      Extract the top three layers into a new file

      Flatten both images and save as .tif

       

      Any ideas?

       

      Even scripting the 1st two steps would be great.I've tried "Merge files into stack", but it won't let me automate the "add open files" part of that.

       

      Thanks.

        • 1. Re: Automate merge files into stack
          JJMack Most Valuable Participant

          I can not tell you how to do it but you could look at the Image processor script the comes with Photoshop fot it has an option to process open documents. Therefore it has code to process all open documents. You may find what your looking for in therr for it also creates new documents.

          1 person found this helpful
          • 2. Re: Automate merge files into stack
            Michael L Hale Level 5

            You can automate loading open docs into a stack using the Load Files into Stack.jsx as long as the documents have a file( either opened from a file or have been saved at least once)

             

            var loadLayersFromScript = true;
            //@includepath "/c/program files/adobe/Adobe Photoshop CS5/Presets/Scripts/"
            //@include "load files into stack.jsx"
            var files = [];
            for(var d =0;d<app.documents.length;d++){
                try{
                    files.push(app.documents[d].fullName.fsName);
                }catch(e){
                    alert(localize('$$$/AdobePlugin/Exposuremerge/Mustsave=Documents must be saved before they can be merged'));
                }
            }
            loadLayers.intoStack(files,true);
            
            • 3. Re: Automate merge files into stack
              jmug45 Level 1

              That's great - I'll just add this into an action and batch process from there.

               

              Thanks.

              • 4. Re: Automate merge files into stack
                ps_10

                Big newb here.... but was hoping to get some advice on how

                to use the script you wrote down here in cs3 extended? I'm trying to use the event script manager to automatically merge all open files without having to click the button in the Load Files into Stack.jsx dialog. Do I save that script you wrote down as a separate java script and load it into the event script manager? ..i tried that and it gives me an error message that says

                 

                Error 24: this.mergeStackElements is not a function.

                Line: 124

                ->       this.mergeStackElements();

                 

                this is in reference to the loadfilesinto stack.jsx file i'm guessing? any suggestions would be greatly appreciated. thank u!

                • 5. Re: Automate merge files into stack
                  Michael L Hale Level 5

                  If I remember correctly Load Files into Stacks was new in CS3. It appears that the running from script part doesn't work in CS3.

                   

                  Also I don't understand how you would use this as an event script. What event are you using?

                  • 6. Re: Automate merge files into stack
                    Paul Riggott Level 6

                    I wonder if the hardcoded includepath was amended to the correct path for CS3?

                     

                    I can't see how it could trigger the event unless it was triggered by a certain number of open documents?

                    • 7. Re: Automate merge files into stack
                      ps_10 Level 1

                      Yea, I am hoping to use the open document trigger for the event script manager to load your script automatically. ...i'm having around 4-5 images open up at once in photoshop. ...then i was hoping to use the event script manager to trigger the load into stack and merge those 4 or 5 images together without having to press any buttons (press the combine open documents)..the images would already be open..the script would combine them together. not sure if it would work but thats the goal. I'll try it out with CS4 if you think it would work.  Thanks for such a quick reply Michael and Paul.

                      • 8. Re: Automate merge files into stack
                        ps_10 Level 1

                        yea...i had updated the include path for CS3...its 32-bit photoshop though...not sure if that may be a problem. thanks

                        • 9. Re: Automate merge files into stack
                          Michael L Hale Level 5

                          It does look like there is an error in the CS3 version of Load Files into Stacks. The function mergeStackElements() is called but never defined. Both the CS4 and CS5 call this.stackLayers(); instead of this.mergeStackElements();

                           

                          If you are willing to edit the Adobe script to make that change it will work in CS3.

                          • 10. Re: Automate merge files into stack
                            ps_10 Level 1

                            Thank you!!!! That works great. ...my only probems are a script alert box that comes up telling me all files must be saved..would like it to just not show up. i'll check to see if i can somehow disable it..delete its reference in the script. Also the script event manager doesn't seem like the best way to combine 4 files this way. since its set to "open document" trigger, the 4 files that open up get combined with each other 4 different ways...loadfilesintostack is working 4 different times. what might be better i think is a script that can automatically load any amount of files in a folder into a single psd file...and only do it once. i've tried to make an action of it but didn't seem to work. if you know anything off the top of your head i'd appreciate it. please don't worry about this if not. Thank you very much! ..tried working with the image processor but had the same problem. combines the images into countless different stacks. thanks

                             

                            ..sorry forgot to mention that the script for combining files in a folder together...if there is one.....would it be possible to not have to click anything...almost be like creating an action and then using the event script manager to trigger that action. understand i might have to have a certain folder specified in the script for the script to know where files are located. thank u!

                            • 11. Re: Automate merge files into stack
                              ps_10 Level 1

                              Been trying to piece together a script from other forum pages...thank u Michael for getting me this far with it.

                               

                              ..modified a auto photomerge script for loadfilesintostack.... however I'm getting an error everytime i run it that says

                              Error 21: undefined is not an object.

                              Line 11:

                              -> var workfolder = folder.selectDialog ('...my folder location');

                               

                              here's what i've got...

                               

                              var loadLayersFromScript = true;
                              //@includepath "/c/Program Files/Adobe/Adobe Photoshop CS4/Presets/Scripts/"
                              //@include "load files into stack.jsx"
                              //@show include

                              psdOpts = new PhotoshopSaveOptions();
                              psdOpts.embedColorProfile = true;
                              psdOpts.alphaChannels = true;
                              psdOpts.layers = true;

                              var workFolder = folder.selectDialog ('/C/Documents and Settings/cbusch/Desktop/Images');
                              var folders = workFolder.getFiles( function( file ) { return file instanceof Folder; } );

                              for( var i = 0; i < folders.length; i++ ) {
                                
                                 var folder = folders[i];
                              var fList = folder.getFiles(/\.(eps|tif|jpg|pdf|psd|exr)$/i);

                                 if( fList.length > 1 ){
                                    loadLayers.intoStack(fList,false);
                                 }
                                 // The merged doc will be the activeDocument
                                 activeDocument.saveAs( new File( fList[0].parent + '/completed.psd' ) , psdOpts, true, Extension.LOWERCASE);
                                 activeDocument.close( SaveOptions.DONOTSAVECHANGES );
                              }

                               

                              thanks for any help

                              • 12. Re: Automate merge files into stack
                                Michael L Hale Level 5

                                selectDialog is a Folder class method so one way to fix would be to use var workFolder = Folder.selectDialog ('/C/Documents and Settings/cbusch/Desktop/Images');

                                 

                                However from looking at your code I don't think that is what you want. You want to use the folder object selectDlg method.

                                 

                                var workFolder = new Folder ('/C/Documents and Settings/cbusch/Desktop/Images');

                                workFolder = workFolder.selectDlg('some useful user prompt');

                                if(workFolder != null){// check to make sure user did select a folder and didn't just cancel dialog

                                // workFolder is valid so rest of the code in this block

                                 

                                 

                                }

                                 

                                For either selectDialog or selectDlg the argument is a user prompt to display in the dialog.

                                • 13. Re: Automate merge files into stack
                                  ps_10 Level 1

                                  Yes, thats definitely what i am looking for....i think, thank u. I'm not sure if i'm reading this right, but i was hoping to avoid all dialog boxes..so maybe selectDialog/selectDlg isn't the way to go. I like selectDlg has a preselected folder in mind though. I was hoping to avoid any user prompt with this script if possible. Basically the script just executes the loadfilesintostack by itself on a preselected folder without an ok/cancel button argument of any kind, no keystrokes necessary. Newb question here.... but is there a way to use something like

                                   

                                  execute

                                  folderObj.execute ('C/~/images'....workFolder)

                                   

                                  anywhere in the script to tell it to automatically use this folder with loadfilesintostack .....and then have the bottom half of the script save it out as a psd? thank u!

                                  • 14. Re: Automate merge files into stack
                                    Michael L Hale Level 5

                                    If you don't want the user to select the folder just use

                                     

                                    var workFolder = new Folder('/C/Documents and Settings/cbusch/Desktop/Images');

                                    • 15. Re: Automate merge files into stack
                                      ps_10 Level 1

                                      perfect. this is what i've got...

                                       

                                      var loadLayersFromScript = true;
                                      //@includepath "/c/Program Files/Adobe/Adobe Photoshop CS4/Presets/Scripts/"
                                      //@include "load files into stack.jsx"
                                      //@show include

                                      psdOpts = new PhotoshopSaveOptions();
                                      psdOpts.embedColorProfile = true;
                                      psdOpts.alphaChannels = true;
                                      psdOpts.layers = true;

                                      var workFolder = new Folder ('/C/Documents and Settings/cbusch/Desktop/Images');

                                      var folders = workFolder.getFiles( function( file ) { return file instanceof Folder; } );

                                      for( var i = 0; i < folders.length; i++ ) {
                                        
                                         var folder = folders[i];
                                      var fList = folder.getFiles(/\.(eps|tif|jpg|pdf|psd|exr)$/i);

                                         if( fList.length > 1 ){
                                            loadLayers.intoStack(fList,false);
                                         }
                                         // The merged doc will be the activeDocument
                                         activeDocument.saveAs( new File( fList[0].parent + '/completed.psd' ) , psdOpts, true, Extension.LOWERCASE);
                                         activeDocument.close( SaveOptions.DONOTSAVECHANGES );

                                       

                                       

                                      when i run the script inside of photoshop it doesn't seem to be doing anything. the folder i have for the newfolder (C~images) has 6 images in them... which i would guess would be combined into one .psd file which would also sit inside that folder? ..i guess where can i specify which folder it goes to? ...the combining and saving i guess doesn't seem to jive. thanks for any help!

                                      • 16. Re: Automate merge files into stack
                                        Michael L Hale Level 5

                                        The script you posted looks for subfolders in workFolder then process each subfolder as a different stack. An easy fix would be for you to make a subfolder in '/C/Documents and Settings/cbusch/Desktop/Images' and place the images in that subfolder.

                                        • 17. Re: Automate merge files into stack
                                          ps_10 Level 1

                                          Yes!! it works. fantastic. thank u so much. is there any way i could get a line of script at the end to close photoshop after the image is saved? thank u!!

                                          • 18. Re: Automate merge files into stack
                                            Rudi M

                                            HI,

                                            I modifid the last script mentioned a little bit for mac users, but I have stil two questions:

                                            -How can I make the script  execute some self made atcions before closing the dcument.

                                            -why does the script only proces one folder in the chosen directory.

                                             

                                            var loadLayersFromScript = true;

                                            //@includepath "/c/Program Files/Adobe/Adobe Photoshop CS4/Presets/Scripts/"

                                            //@include "load files into stack.jsx"

                                            //@show include

                                            psdOpts = new PhotoshopSaveOptions();

                                            psdOpts.embedColorProfile = true;

                                            psdOpts.alphaChannels = true;

                                            psdOpts.layers = true;

                                            var workFolder = new Folder ('~/Desktop/Images');

                                            var folders = workFolder.getFiles( function( file ) { return file instanceof Folder; } );

                                            for( var i = 0; i < folders.length; i++ )

                                              

                                               var folder = folders[i];

                                            var fList = folder.getFiles(/\.(eps|tif|jpg|pdf|psd|exr)$/i);

                                               if( fList.length > 1 ){

                                                  loadLayers.intoStack(fList,false);

                                               }

                                               // The merged doc will be the activeDocument

                                               activeDocument.saveAs( new File( fList[0].parent + '/completed.psd' ) , psdOpts, true, Extension.LOWERCASE);

                                               activeDocument.close( SaveOptions.DONOTSAVECHANGES );

                                            • 19. Re: Automate merge files into stack
                                              Michael L Hale Level 5

                                              To run your action just add a doAction() line just before activeDocument.saveAs();

                                               

                                              It should create a stacked document for each subfolder that has files with any of those 6 formants. I would guess that if it doesn't create a stacked document for a subfolder that is because it didn't find at least two files in that folder.

                                              • 20. Re: Automate merge files into stack
                                                Rudi M Level 1

                                                Thank you.

                                                And how do I recal the specifid action in the doAction(the part between the brackets?), do I just fill in the name of the action. I'm sorry but I'm not used to script myself

                                                 

                                                My test situation is a folder "images" on the Desktop with 2 folders in it with valid documents, after running one folder the schript seems to be stopping..

                                                • 21. Re: Automate merge files into stack
                                                  Michael L Hale Level 5

                                                  doAction('actionName','actionSet');

                                                   

                                                  You might try adding braces to the for loop;

                                                   

                                                  for( var i = 0; i < folders.length; i++ ) {

                                                   

                                                  Then add the closing brace after the activeDocument.close() line. Maybe the lack for braces causes the script to only loop once.

                                                  • 22. Re: Automate merge files into stack
                                                    Rudi M Level 1

                                                    Oh yes, this is nice, thanks a lot.

                                                     

                                                    One additional question, can I change the naming part.

                                                    Now every file in every subfolder is called "completed.psd"

                                                    How do I manage to get a list type of name completed_01, completed_02 etc.

                                                    Not very urgent, but would be nice if you can help my out with that.

                                                     

                                                    Then I'm really done

                                                    • 23. Re: Automate merge files into stack
                                                      zephyrandy

                                                      Michael L Hale,

                                                      Thanks for this bit of code. It is exactly what I need to automate an action that combines two open files without the prompt. Only thing I would like to ask your help now is how would I disable the auto-align feature using this script? I took your code (from July 14, 2010) and saved it as a .jsx but when using the script the auto-align layers feature is called up automatically and is slows the whole action down substantially. I tried digging around the the original load files into stack.jsx for the answer but could not figure it out.

                                                      Any suggestions to add to your bit of code to disable that feature. I'm running PS CC. Thanks so much!