Photoshop: Batch Replace Smart Objects - Script Error. Please Help
Dear All,
I've been looking for a Photoshop script for a long time, that could help me batch replace images in a smart object (essentially just trying to batch convert flat 1125x750px images to 3D images).
As I'm quite the Photoshop beginner, I had someone create a mockup file and he found an existing script to work with on these forums.
So here's what I have:
- a mockup file of an image set as a transformed smart object
- a folder of images resized to fit said smart object
This is what I would like the script to do:
- for every image in said folder
- replace smart object with images
Your man sent me a video how to execute the script and it worked just fine on his computer (Windows 7). Problem is that it doesn't work on mine (Windows 7 and Windows 10). I've tried on several computers (some had better specs than his), but unfortunately to no avail. He used a legal version of Photoshop CC 2018 and so did I, so it wouldn't have to do with that. We both can't find the issue.
The error message that I get: ''executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO''. I use the following script:
// Replace SmartObject’s Content and Save as JPG
// 2017, use it at your own risk
// Via @10354895 B: https://graphicdesign.stackexchange.com/questions/92796/replacing-a-smart-object-in-bulk-with-photos...
// JPG code from here: https://forums.adobe.com/thread/737789
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theLayer = myDocument.activeLayer;
// JPG Options;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 8;
// Check if layer is SmartObject;
if (theLayer.kind != "LayerKind.SMARTOBJECT") {
alert("selected layer is not a smart object")
} else {
// Select Files;
if ($.os.search(/windows/i) != -1) {
var theFiles = File.openDialog("please select files", "*.psd;*.tif;*.jpg", true)
} else {
var theFiles = File.openDialog("please select files", getFiles, true)
};
if (theFiles) {
for (var m = 0; m < theFiles.length; m++) {
// Replace SmartObject
theLayer = replaceContents(theFiles
var theNewName = theFiles
// Save JPG
myDocument.saveAs((new File(thePath + "/" + theName + "_" + theNewName + ".jpg")), jpgSaveOptions, true,Extension.LOWERCASE);
}
}
}
};
// 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
};
};
// 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
};
Please find screenshots attached of the error message that I get + layers and channels at the moment the script fails. Please note that I've blurred out the smart object design as I paid for it - would like to keep it private and not for all to view.
If someone could help me out I'd really REALLY appreciate it. I've literally been caving myself into my apartment for the past 4 days trying to resolve this.

