If anyone is interested, I managed to get this sorted. Here is the script that will batch replace 3 smart objects within a PSD using files saved in 3 separate folders. The 3 smart objects need to be called 'Left' , 'Right', 'Middle' but I'm sure this can be easily edited for those with any coding knowledge. It also helps that the files in each folder all use the same file name system so that the images are paired up as you want. The script exports each iteration as a jpeg in the same folder loction as the PSD:
// Replace 'Left,' 'Middle,' and 'Right' Smart Objects' Content and Save as JPEG
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
// Find 'Left,' 'Middle,' and 'Right' layers
var layer1 = findLayerByName("Left");
var layer2 = findLayerByName("Middle");
var layer3 = findLayerByName("Right");
// JPG Options
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;
// Check if all layers are found
if (layer1 && layer2 && layer3) {
// Select Files for 'Left' Smart Object
var folder1 = Folder.selectDialog("Select folder for the 'Left' smart object images");
if (folder1) {
var files1 = folder1.getFiles(/\.(psd|tif|jpg)$/i);
// Select Files for 'Middle' Smart Object
var folder2 = Folder.selectDialog("Select folder for the 'Middle' smart object images");
if (folder2) {
var files2 = folder2.getFiles(/\.(psd|tif|jpg)$/i);
// Select Files for 'Right' Smart Object
var folder3 = Folder.selectDialog("Select folder for the 'Right' smart object images");
if (folder3) {
var files3 = folder3.getFiles(/\.(psd|tif|jpg)$/i);
// Check if all folders have the same number of files
if (files1.length === files2.length && files1.length === files3.length) {
for (var i = 0; i < files1.length; i++) {
// Replace 'Left,' 'Middle,' and 'Right' Smart Objects
layer1 = replaceContents(files1[i], layer1);
layer2 = replaceContents(files2[i], layer2);
layer3 = replaceContents(files3[i], layer3);
var theNewName = files1[i].name.match(/(.*)\.[^\.]+$/)[1];
// Save as JPEG
myDocument.saveAs(new File(thePath + "/" + theName + "_" + theNewName + ".jpg"), jpgSaveOptions, true);
}
} else {
alert("All folders should contain the same number of images.");
}
}
}
}
} else {
alert("One or more of the 'Left,' 'Middle,' or 'Right' smart objects were not found in the document.");
}
}
// Get PSDs, TIFs, and JPGs from files
function getFiles(theFile) {
if (theFile.name.match(/\.(psd|tif|jpg)$/i) !== null || theFile.constructor.name === "Folder") {
return true;
}
}
// Find a layer by name
function findLayerByName(layerName) {
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
if (layers[i].name === layerName) {
return layers[i];
}
}
return null; // Layer not found
}
// Replace SmartObject Contents
function replaceContents(newFile, theSO) {
app.activeDocument.activeLayer = theSO;
var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc3.putPath(idnull, new File(newFile));
var idPgNm = charIDToTypeID("PgNm");
desc3.putInteger(idPgNm, 1);
executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
return app.activeDocument.activeLayer;
}