11 Replies Latest reply on Oct 14, 2016 5:16 AM by SuperMerlin

    Workflow Help! Batch Load files into Layers and save possible?

    m0987

      I've been manually doing this for years and am certain there's a script somewhere that could help.

       

      I have say 10 folders with images in them, Each folder will have images selected usually 20 and then turned into 1 document.

       

      I manually load files into layers from Bridge for my selected images one by one every day and with the new update it seems the que function has also dissapeared( Not that it was reliable).

      So I have to Baby sit my computer, wait till the document is loaded , Save , Close and then push go again on the next Composite. this sucks..

       

      I need a script that can basically batch load files into layers , save as PSD (Custom location) , and close but do this for more than 1 document.

      I want to be able to que multiple instances of this and then push go.

       

      I have currently a script that can load folders into layers If this could be batched so I can select Multiple Folders at once and it makes a single document from each folder that would be excellent?

       

      1 step further - Could each document be renamed when auto saving to the folder name it came from?

       

      any help would be so great

        • 1. Re: Workflow Help! Batch Load files into Layers and save possible?
          Tomas Sinkunas Adobe Community Professional

          Doable.

          Are image sizes equal?

           

          Can you share your current script that loads folders to layers? I'll try to make it work with multiple folders.

          • 2. Re: Workflow Help! Batch Load files into Layers and save possible?
            Tomas Sinkunas Adobe Community Professional

            Any ways, here's my approach.

            NOTE: There's no way to select multiple folders - only multiple file selections are allowed.

             

            have subfolders be nested in Root Folder, and select this Root Folder via script. Like this:

             

            - Root Folder:

                - Folder A:

                      - image.jpg,

                      - image.jpg,

                - Folder B:

                      - image.jpg,

                      - image.jpg,

                      - image.jpg,

                      - image.jpg,

                - Folder C:

                      - image.jpg,

                      - image.jpg

             

            ... etc

             

            Script will open Folder A and batch load images to single PSD file and save it as "Folder A.psd". Then will proceed to next folder Folder B and will work with those images and will save file as "Folder B.psd" etc. Hope this makes sense.

             

            // Name: Batch Load Files into Layers.jsx
            // Version: 1.0
            // Release Date: 2016 10 13
            //
            // Developer: Tomas Sinkunas
            // URL: www.rendertom.com
            // 
            // Description:
            // Select root folder that contains subfolders. if subfolders contain
            // image files, then all images from current subfolder will be loaded
            // to single Pthoshop File and saved to disk.
            //
            //
            // This script is provided "as is," without warranty of any kind,
            // expressed or implied. In no event shall author be held liable
            // for any damages arising from the use of this script.
            
            
            batchLoadFiles();
            
            
            function batchLoadFiles() {
              #target photoshop
            
            
              var config = {
              folders : [],
              outputFolder : "",
              }
            
            
              buildUI();
            
            
              function buildUI() {
              var btnSize = 24;
            
            
              var win = new Window('dialog', "Whatever, dude");
            
            
              win.spacing = 10;
              win.alignChildren = ["fill", "fill"];
            
            
              win.group1 = win.add("group");
              win.btnSelectFolders = win.group1.add("button", undefined, "Select Root Folder");
            
            
              win.group2 = win.add("group");
              win.stOutputFolder = win.group2.add('statictext', undefined, "Output Folder");
              win.etOutputFolder = win.group2.add('edittext', undefined, config.outputFolder);  
              win.btnSelectOutputFolder = win.group2.add('button', undefined, "...");
            
            
              win.group3 = win.add("group");
              win.btnCloseWindow = win.group3.add('button',undefined, "Close", {name:'close'});  
              win.btnRunScript = win.group3.add('button',undefined, "Run Script", {name:'run Script'});  
            
            
              // Resize Buttons
              win.stOutputFolder.preferredSize.width = 120;
              win.etOutputFolder.preferredSize.width = 200;
              win.btnSelectOutputFolder.preferredSize.width = btnSize * 2;
            
              win.btnSelectFolders.alignment = 
              win.btnCloseWindow.alignment = 
              win.btnRunScript.alignment = ["fill", "fill"];
            
            
              // button actions
              win.btnSelectFolders.onClick = function () {
              var rootFolder = Folder.selectDialog("Select root folder");
              if (rootFolder === null) return;
            
            
              var foldersArray = getFolders(rootFolder);
              if (foldersArray.length === 0) {
              alert("Selected folder does not contain any folders inside of it.");
              return;
              }
            
            
              config.folders = foldersArray;
            
            
              this.text = "Root Folder \"" + decodeURI(rootFolder.name) + "\" with " + foldersArray.length + " subfolders";
              }
            
            
              win.btnSelectOutputFolder.onClick = function() {
              var outputFolder = Folder.selectDialog("Select output folder");
              if (outputFolder) {
              win.etOutputFolder.text = outputFolder.fsName;
              config.outputFolder = outputFolder.fsName;
              }
              }
            
            
              win.btnCloseWindow.onClick = function() {
              win.close();
              }
            
            
              win.btnRunScript.onClick = function() {
            
            
              if (config.folders.length === 0) {
              alert("Select Root Folder first");
              win.btnSelectFolders.active = true; return;
              } else if (config.outputFolder === "" || !Folder(config.outputFolder).exists) {
              alert("Output Folder does not exist\nPlease set Output Folder and try again");
              win.etOutputFolder.active = true; return;
              }
            
            
              win.close();
            
            
              main();
              }
            
            
              win.show();
              }
            
            
              function main() {
              try {
              for (var i = 0, il = config.folders.length; i < il; i ++) {
              var folder = config.folders[i];
              var files = folder.getFiles(/\.(jpg|tif|psd|bmp|gif|png|)$/i);
              if (files.length > 0) {
              for (var f = 0, fl = files.length; f < fl; f++) {
              var file = files[f];
              if (f === 0) {
              var masterDoc = open(file);
              masterDoc.layers[0].isBackgroundLayer = false;
              masterDoc.layers[0].name = decodeURI ( masterDoc.name );
              } else {
              var doc = open(file);
              var layer = doc.layers[0].duplicate(masterDoc);
            
              app.activeDocument = masterDoc;
              layer.name = decodeURI ( doc.name );
            
            
              doc.close();
              }
              }
            
            
              var outputPsdFile = config.outputFolder + "/" + folder.name + ".psd";
              savePSD(outputPsdFile);
              masterDoc.close();
              }
              }
              } catch(e) {
              alert(e.toString() + "\nLine: " + e.line.toString());
              }
              }
            
            
              function savePSD(saveFile) {
              psdSaveOptions = new PhotoshopSaveOptions();
              psdSaveOptions.embedColorProfile = true;
              psdSaveOptions.alphaChannels = true;
              activeDocument.saveAs(File(saveFile), psdSaveOptions, false, Extension.LOWERCASE);
              }
            
            
              function getFolders(rootFolder) {
              var folders = [];
              var folderItems = rootFolder.getFiles();
            
            
              for (var i = 0, il = folderItems.length; i < il; i ++) {
              var curItem = folderItems[i];
              if (curItem.constructor.name == "Folder") {
              folders.push(curItem);
              }
              }
              return folders;
              }
            }
            
            • 3. Re: Workflow Help! Batch Load files into Layers and save possible?
              m0987 Level 1

              You beautiful genius!

               

              Image sizes are all the same. however This only seems to work with Jpegs, Anyway to use raw images and load with default raw setting/Preset set as defualt)

               

              The folder approach you have will work perfectly,

               

              Out of curiosity is it possible to target only rated images , for example only load files with a 1 star rating and ignore the rest?

              This would save relocating selected images?

              • 4. Re: Workflow Help! Batch Load files into Layers and save possible?
                Tomas Sinkunas Adobe Community Professional

                Hi.

                Regarding rated images - I dont think it's doable. Well, not that it's impossible, but definitely beyond photoshop scripting scope.

                 

                And I didnt understand the rest of your message sorry. You say it only works with jpegs? Or you need it to work with jpegs only?

                 

                Raw images? What are those?

                 

                Sorry, this might be a language barrier, but I wasnt able to understand.

                • 5. Re: Workflow Help! Batch Load files into Layers and save possible?
                  m0987 Level 1

                  Hi thanks for your reply

                   

                  By raw images I mean Images in camera raw format such as .NEF ( Nikon Cameras ) or .CR2 ( Canon ).

                  At the moment the script only works with .Jpeg files which is not ideal.

                  • 6. Re: Workflow Help! Batch Load files into Layers and save possible?
                    Tomas Sinkunas Adobe Community Professional

                    Agh, ok, got it. Will take a look.

                    I dont have access to such files - can you send over few of those so I could test?

                    • 7. Re: Workflow Help! Batch Load files into Layers and save possible?
                      Tomas Sinkunas Adobe Community Professional

                      Here, try this.

                      I dont have CR2 of NEF files to test this on, so not sure if it works 100%. Let me know if it does:)

                       

                      // Name: Batch Load Files into Layers.jsx
                      // Version: 1.0
                      // Release Date: 2016 10 13
                      //
                      // Developer: Tomas Sinkunas
                      // URL: www.rendertom.com
                      //
                      // Description:
                      // Select root folder that contains subfolders. if subfolders contain
                      // image files, then all images from current subfolder will be loaded
                      // to single Pthoshop File and saved to disk.
                      //
                      //
                      // This script is provided "as is," without warranty of any kind,
                      // expressed or implied. In no event shall author be held liable
                      // for any damages arising from the use of this script.
                      
                      
                      batchLoadFiles();
                      
                      
                      function batchLoadFiles() {
                        #target photoshop
                      
                      
                        var config = {
                        folders : [],
                        outputFolder : "",
                        extensions : "jpg, tif, psd, bmp, gif, png, nef, cr2"
                        }
                      
                      
                        buildUI();
                      
                      
                        function buildUI() {
                        var btnSize = 24;
                      
                      
                        var win = new Window('dialog', "Whatever, dude");
                      
                      
                        win.spacing = 10;
                        win.alignChildren = ["fill", "fill"];
                      
                      
                        win.group1 = win.add("group");
                        win.btnSelectFolders = win.group1.add("button", undefined, "Select Root Folder");
                      
                      
                        win.group2 = win.add("group");
                        win.stOutputFolder = win.group2.add('statictext', undefined, "Output Folder");
                        win.etOutputFolder = win.group2.add('edittext', undefined, config.outputFolder); 
                        win.btnSelectOutputFolder = win.group2.add('button', undefined, "...");
                      
                      
                        win.group3 = win.add("group");
                        win.btnCloseWindow = win.group3.add('button',undefined, "Close", {name:'close'}); 
                        win.btnRunScript = win.group3.add('button',undefined, "Run Script", {name:'run Script'}); 
                      
                      
                        // Resize Buttons
                        win.stOutputFolder.preferredSize.width = 120;
                        win.etOutputFolder.preferredSize.width = 200;
                        win.btnSelectOutputFolder.preferredSize.width = btnSize * 2;
                      
                        win.btnSelectFolders.alignment =
                        win.btnCloseWindow.alignment =
                        win.btnRunScript.alignment = ["fill", "fill"];
                      
                      
                        // button actions
                        win.btnSelectFolders.onClick = function () {
                        var rootFolder = Folder.selectDialog("Select root folder");
                        if (rootFolder === null) return;
                      
                      
                        var foldersArray = getFolders(rootFolder);
                        if (foldersArray.length === 0) {
                        alert("Selected folder does not contain any folders inside of it.");
                        return;
                        }
                      
                      
                        config.folders = foldersArray;
                      
                      
                        this.text = "Root Folder \"" + decodeURI(rootFolder.name) + "\" with " + foldersArray.length + " subfolders";
                        }
                      
                      
                        win.btnSelectOutputFolder.onClick = function() {
                        var outputFolder = Folder.selectDialog("Select output folder");
                        if (outputFolder) {
                        win.etOutputFolder.text = outputFolder.fsName;
                        config.outputFolder = outputFolder.fsName;
                        }
                        }
                      
                      
                        win.btnCloseWindow.onClick = function() {
                        win.close();
                        }
                      
                      
                        win.btnRunScript.onClick = function() {
                      
                      
                        if (config.folders.length === 0) {
                        alert("Select Root Folder first");
                        win.btnSelectFolders.active = true; return;
                        } else if (config.outputFolder === "" || !Folder(config.outputFolder).exists) {
                        alert("Output Folder does not exist\nPlease set Output Folder and try again");
                        win.etOutputFolder.active = true; return;
                        }
                      
                      
                        win.close();
                      
                      
                        main();
                        }
                      
                      
                        win.show();
                        }
                      
                      
                        function main() {
                        try {
                      
                      
                        var startDisplayDialogs = app.displayDialogs;
                        app.displayDialogs = DialogModes.NO;
                      
                      
                        var extensionList = config.extensions.replace(/, /g, "|");
                      
                        for (var i = 0, il = config.folders.length; i < il; i ++) {
                        var folder = config.folders[i];
                      
                        var files = folder.getFiles(new RegExp("\.(" + extensionList + ")$","i"));
                        if (files.length > 0) {
                        for (var f = 0, fl = files.length; f < fl; f++) {
                        var file = files[f];
                        if (f === 0) {
                        var masterDoc = open(file);
                        masterDoc.layers[0].isBackgroundLayer = false;
                        masterDoc.layers[0].name = decodeURI ( masterDoc.name );
                        } else {
                        var doc = open(file);
                        var layer = doc.layers[0].duplicate(masterDoc);
                      
                        app.activeDocument = masterDoc;
                        layer.name = decodeURI ( doc.name );
                      
                      
                        doc.close();
                        }
                        }
                      
                      
                        var outputPsdFile = config.outputFolder + "/" + folder.name + ".psd";
                        savePSD(outputPsdFile);
                        masterDoc.close();
                        }
                        }
                      
                      
                        app.displayDialogs = startDisplayDialogs;
                      
                      
                      
                      
                        } catch(e) {
                        alert(e.toString() + "\nLine: " + e.line.toString());
                        }
                        }
                      
                      
                        function savePSD(saveFile) {
                        psdSaveOptions = new PhotoshopSaveOptions();
                        psdSaveOptions.embedColorProfile = true;
                        psdSaveOptions.alphaChannels = true;
                        activeDocument.saveAs(File(saveFile), psdSaveOptions, false, Extension.LOWERCASE);
                        }
                      
                      
                        function getFolders(rootFolder) {
                        var folders = [];
                        var folderItems = rootFolder.getFiles();
                      
                      
                        for (var i = 0, il = folderItems.length; i < il; i ++) {
                        var curItem = folderItems[i];
                        if (curItem.constructor.name == "Folder") {
                        folders.push(curItem);
                        }
                        }
                        return folders;
                        }
                      }
                      
                      • 8. Re: Workflow Help! Batch Load files into Layers and save possible?
                        m0987 Level 1

                        I had a link But this worked. It now Accepts Raw Files. I added

                        158. doc.close(SaveOptions.DONOTSAVECHANGES);

                        And its perfect for .psd files

                         

                        I've now realized I meant to write that the document needs to be saved as .PSB Not PSD.

                         

                        Is this a difficult change?

                        • 9. Re: Workflow Help! Batch Load files into Layers and save possible?
                          Tomas Sinkunas Adobe Community Professional

                          Not difficult at all when you know how to do this, right?

                          • 10. Re: Workflow Help! Batch Load files into Layers and save possible?
                            m0987 Level 1

                            I dont know ive been looking online for ages now trying but it seems impossible to save as a .psb in a script? i stumbled across that last line in another forum and problem solved the awesome one you have done.

                            • 11. Re: Workflow Help! Batch Load files into Layers and save possible?
                              SuperMerlin Level 5

                              Here is a fuction that should work to save as PSB...

                              function savePSB(saveFile) { 
                              var desc1 = new ActionDescriptor(); 
                              var desc2 = new ActionDescriptor(); 
                              desc2.putBoolean( stringIDToTypeID('maximizeCompatibility'), true ); 
                              desc1.putObject( charIDToTypeID('As  '), charIDToTypeID('Pht8'), desc2 ); 
                              desc1.putPath( charIDToTypeID('In  '), new File(saveFile) ); 
                              desc1.putBoolean( charIDToTypeID('LwCs'), true ); 
                              executeAction( charIDToTypeID('save'), desc1, DialogModes.NO ); 
                              };