2 Replies Latest reply on Aug 25, 2016 9:15 AM by Dogspods

    Import subfolders as layers....

    Dogspods

      I need a script that will import all subfolders as layers, either as an individual PSD file for each subfolder or as a single file (first option is preferable).

      I've been using this script so far (found here: Batch subfolder images to layer stacks, then to sprites. )

       

      // select folder, create files with the contents of one of the subfolders each as layers and save them to the folder; 

      • // use it at your own risk; 
      • #target photoshop 
      • // select a folder; 
      • var sourceFolder = Folder.selectDialog("Select folder"); 
      • if (sourceFolder) { 
      • // the psd options; 
      • psdOpts = new PhotoshopSaveOptions(); 
      • psdOpts.embedColorProfile = true; 
      • psdOpts.alphaChannels = false; 
      • psdOpts.layers = true; 
      • psdOpts.spotColors = true; 
      • // get the contents as one array per folder; 
      • var items = retrieveFiles(sourceFolder, [[]]); 
      • // iterate through; 
      • for (var m = 1; m < items.length; m++) { 
      •           var thisArray = items[m]; 
      •           var folderName = thisArray[0].parent.name; 
      • // open file; 
      •           var theImage = app.open(File(thisArray[0])); 
      •           for (var n = 1; n < thisArray.length; n++) { 
      • // place rest of array; 
      •                     var theLayer = placeScaleFile(thisArray[n], 0, 0, 100); 
      •                     }; 
      • // save the stacked file; 
      •           theImage.saveAs(new File(sourceFolder+"/"+folderName+".psd"),psdOpts,false); 
      • // close; 
      •           theImage.close(SaveOptions.DONOTSAVECHANGES); 
      •           }; 
      • }; 
      • ////// get from subfolders ////// 
      • function retrieveFiles (theFolder, theFiles) { 
      •           if (!theFiles) {var theFiles = [[]]}; 
      •           var theContent = theFolder.getFiles(); 
      •           for (var n = 0; n < theContent.length; n++) { 
      •                     var theObject = theContent[n]; 
      •                     if (theObject.constructor.name == "Folder") { 
      •                               theFiles.push(new Array) 
      •                               retrieveFiles(theObject, theFiles) 
      •                               }; 
      •                     if (theObject.name.match(new RegExp(/\.(jpe|jpg|jpeg|gif|png|tif|tiff|bmp|psd|dng|pict|eps|raw|rw2|crw|cr2)/i)) != null) { 
      •                               theFiles[theFiles.length - 1].push(theObject) 
      •                               } 
      •                     }; 
      •           return theFiles 
      •           }; 
      • ////// get psds, tifs and jpgs from files ////// 
      • function getFiles (theFile) { 
      •     if (theFile.name.match(/\.(eps|ai|jpg|tif|psd|pdf|)$/i)) { 
      •         return true 
      •         }; 
      •           }; 
      • ////// place ////// 
      • function placeScaleFile (file, xOffset, yOffset, theScale) { 
      • // ======================================================= 
      • var idPlc = charIDToTypeID( "Plc " ); 
      •     var desc5 = new ActionDescriptor(); 
      •     var idnull = charIDToTypeID( "null" ); 
      •     desc5.putPath( idnull, new File( file ) ); 
      •     var idFTcs = charIDToTypeID( "FTcs" ); 
      •     var idQCSt = charIDToTypeID( "QCSt" ); 
      •     var idQcsa = charIDToTypeID( "Qcsa" ); 
      •     desc5.putEnumerated( idFTcs, idQCSt, idQcsa ); 
      •     var idOfst = charIDToTypeID( "Ofst" ); 
      •         var desc6 = new ActionDescriptor(); 
      •         var idHrzn = charIDToTypeID( "Hrzn" ); 
      •         var idPxl = charIDToTypeID( "#Pxl" ); 
      •         desc6.putUnitDouble( idHrzn, idPxl, xOffset ); 
      •         var idVrtc = charIDToTypeID( "Vrtc" ); 
      •         var idPxl = charIDToTypeID( "#Pxl" ); 
      •         desc6.putUnitDouble( idVrtc, idPxl, yOffset ); 
      •     var idOfst = charIDToTypeID( "Ofst" ); 
      •     desc5.putObject( idOfst, idOfst, desc6 ); 
      •     var idWdth = charIDToTypeID( "Wdth" ); 
      •     var idPrc = charIDToTypeID( "#Prc" ); 
      •     desc5.putUnitDouble( idWdth, idPrc, theScale ); 
      •     var idHght = charIDToTypeID( "Hght" ); 
      •     var idPrc = charIDToTypeID( "#Prc" ); 
      •     desc5.putUnitDouble( idHght, idPrc, theScale ); 
      •     var idLnkd = charIDToTypeID( "Lnkd" ); 
      •     desc5.putBoolean( idLnkd, true ); 
      • executeAction( idPlc, desc5, DialogModes.NO ); 
      • return app.activeDocument.activeLayer; 
      • }; 

       

      It's almost perfect for my needs but would be better if the images were imported as standard layers and not smart objects.