Batch Creation PSD files from images

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

Dunkelzahn
Posts: 2
Joined: Mon Apr 27, 2020 11:03 am

Batch Creation PSD files from images

Post by Dunkelzahn »

Hey there,

while being modestly good at scripting in After Effects and 3DS Max, I´m a relative newbie to Photoshop scripting. Currently I´m setting up a simple pipeline to process 250 turntable photo sets. I´ve come pretty far by using Paul Rigotts "Run Action" script and combining it with my action snippets.

This is a truely great script by the way and it has helped me to automate all my tasks except one:

I have a folder with a set of subfolders in it. Inside each subfolder are a set of jpg images. I need a batch process, which goes through each of the subfolders and creates a PSD with all of the images inside it and names the PSD with the subfolder name. The image resolution of the images can be used , or the PSD can be created with the following settings: 4096x4096 px, RBG color space, 72 dpi.

While this may be done with "Load from stack" for a single file I will need this batch process to run over night for all 250 image sets.

Can somebody point me in the right direction, as I am having a hard time setting this up on my own. Maybe something like this has already been written and I just have overlooked it in my forum searches.

Thank you and best regards

Dunkelzahn
e_samurai
Posts: 3
Joined: Tue Apr 28, 2020 3:14 pm

Re: Batch Creation PSD files from images

Post by e_samurai »

I have this exact situation! I tried searching online and actually found this page here:
But whenever I tried running it in Photoshop (CS6 and CC2015) it throws an error of
TypeError: Undefined is not an object
II'm pretty novice with JS myself too, so I actually don't know how to handle this and would appreciate any help a lot!
Geoff
Posts: 10
Joined: Thu Jan 24, 2019 8:18 pm

Re: Batch Creation PSD files from images

Post by Geoff »

Try this...

Code: Select all

#target photoshop;
app.bringToFront();
main();
function main(){
try{
var folders =[];
var topLevel = Folder.selectDialog("Please select top level folder");	
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var f in folders){
var fileList =folders[f].getFiles(/\.(jpg)$/i);
if(fileList.length < 1) continue;
stackFiles(fileList);
var saveFile = File( decodeURI(folders[f]) + "/" + decodeURI(folders[f].name) + ".psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
}catch(e){$.writeln(e + "\n" + e.line);}
};

function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
var fileFoldObj = fileFolderArray[i];
if ( fileFoldObj instanceof File ) {} else {
destArray.push( Folder(fileFoldObj) );
FindAllFolders( fileFoldObj.toString(), destArray );
		}
	}
	return destArray;
};
function stackFiles(files){
try{
var loadLayersFromScript = true;
$.evalFile(app.path + "/" +  localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts") + "/Load Files into Stack.jsx");
loadLayers.intoStack(files);
}catch(e){$.writeln(e + "\n" + e.line);}
};
function SavePSD(saveFile){ 
psdSaveOptions = new PhotoshopSaveOptions(); 
psdSaveOptions.embedColorProfile = true; 
psdSaveOptions.alphaChannels = true;  
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE); 
};

e_samurai
Posts: 3
Joined: Tue Apr 28, 2020 3:14 pm

Re: Batch Creation PSD files from images

Post by e_samurai »

Geoff wrote: Wed Apr 29, 2020 10:58 am Try this...

Code: Select all

#target photoshop;
app.bringToFront();
main();
function main(){
try{
var folders =[];
var topLevel = Folder.selectDialog("Please select top level folder");	
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var f in folders){
var fileList =folders[f].getFiles(/\.(jpg)$/i);
if(fileList.length < 1) continue;
stackFiles(fileList);
var saveFile = File( decodeURI(folders[f]) + "/" + decodeURI(folders[f].name) + ".psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
}catch(e){$.writeln(e + "\n" + e.line);}
};

function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
var fileFoldObj = fileFolderArray[i];
if ( fileFoldObj instanceof File ) {} else {
destArray.push( Folder(fileFoldObj) );
FindAllFolders( fileFoldObj.toString(), destArray );
		}
	}
	return destArray;
};
function stackFiles(files){
try{
var loadLayersFromScript = true;
$.evalFile(app.path + "/" +  localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts") + "/Load Files into Stack.jsx");
loadLayers.intoStack(files);
}catch(e){$.writeln(e + "\n" + e.line);}
};
function SavePSD(saveFile){ 
psdSaveOptions = new PhotoshopSaveOptions(); 
psdSaveOptions.embedColorProfile = true; 
psdSaveOptions.alphaChannels = true;  
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE); 
};

Thanks a lot for your help! It didn't work the first time though, so I thought I'd look at the extensions and found only JPG. By adding my desired extensions to that line it worked! Something like this:

Code: Select all

var fileList =folders[f].getFiles(/\.(jpg|png|tiff|tga)$/i);
But something else happened, it seemed to open each sub-folder in a separate PS file, load all the images inside, then close. It did that sequentially for the 2 subfolders I had and didn't add them to groups nor keep them open in PS.

Any idea why?
Dunkelzahn
Posts: 2
Joined: Mon Apr 27, 2020 11:03 am

Re: Batch Creation PSD files from images

Post by Dunkelzahn »

Wow, thank you very much, Jeff.
Just did a test with a dummy setup..works like a charm. You even thought about closing the files after saving them.

Thumbs up to you and thank you again :)
Last edited by Dunkelzahn on Wed Apr 29, 2020 3:42 pm, edited 2 times in total.
e_samurai
Posts: 3
Joined: Tue Apr 28, 2020 3:14 pm

Re: Batch Creation PSD files from images

Post by e_samurai »

Wow, seems that I missed that each folder is saved into a separate PSD! Brilliant. Thanks Jeff and thanks OP for bringing that up in the first place!