0

My goal is to batch process multiple PSD wall art mockups, replacing the smart objects within each mockup with several image files.

I modified someone’s script for my wall art mockup. My aims to automate this process by iterating through a list of image files and replacing the smart objects in the mockups accordingly. However, despite my efforts, I have encountered difficulties in getting the script to work as intended.

One specific issue I've encountered is the image doesnt resize fit within the picture frame, it enlarges smart object file. I have verified that the file paths are correct and the image files exist at the specified locations. Despite my troubleshooting attempts, I have been unable to resolve this error.

Furthermore, I would like to know if it is possible to utilize multiple PSD wall art mockups in the batch processing script or if I need to restrict it to a single mockup. I am unsure if there are any limitations or specific considerations when handling multiple mockups in a batch process.

I would greatly appreciate any guidance, insights, or suggestions you could provide to help me troubleshoot and resolve the issues I am facing. Additionally, if there are any best practices or recommended approaches for batch processing PSD mockups with smart object replacements, I would be grateful to learn about them.


#target photoshop
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var soLayer = doc.activeLayer;
if (soLayer.kind == LayerKind.SMARTOBJECT) {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var obj = executeActionGet(ref).getObjectValue(stringIDToTypeID("smartObjectMore"));
var soSize = obj.getObjectValue(stringIDToTypeID("size"));
var soWidth = soSize.getDouble(stringIDToTypeID("width"));
var soHeight = soSize.getDouble(stringIDToTypeID("height"));
var res = obj.getDouble(charIDToTypeID("Rslt"));

// Source file for the mockup
var mockupFilePaths = [
"/Volumes/Epefany/Mock-Ups/Wall Art Template/bedroom boho.psd",
"/Volumes/Epefany/Mock-Ups/Wall Art Template/bluelivingroom.psd",
"/Volumes/Epefany/Mock-Ups/Wall Art Template/Manwallart.psd",
"/Volumes/Epefany/Mock-Ups/Wall Art Template/squareblackframe.psd",
"/Volumes/Epefany/Mock-Ups/Wall Art Template/traditionalbrown.psd",
"/Volumes/Epefany/Mock-Ups/Wall Art Template/Trendy-Frame-Mockup-Template-Bundle/Trend Floating Canvas/Floating Trend frame HR 3.psd",
"/Volumes/Epefany/Mock-Ups/Wall Art Template/Trendy-Frame-Mockup-Template-Bundle/Trend Frame /Trend frame 3.psd",
"/Volumes/Epefany/Mock-Ups/Wall Art Template/Trendy-Frame-Mockup-Template-Bundle/Trend Floating Canvas/Floating Trend frame HR 3.psd"
];
var mockupFileIndex = 0; // Index of the selected mockup file
var scrDocFile = new File(mockupFilePaths[mockupFileIndex]);

var scrDoc = open(scrDocFile);
app.preferences.rulerUnits = Units.PIXELS;

scrWidth = scrDoc.width.value;
scrHeight = scrDoc.height.value;

var widthRatio = soWidth / scrWidth;
var heightRatio = soHeight / scrHeight;

var widthIn = soWidth / res;
var heightIn = soHeight / res;
app.activeDocument = scrDoc;
var resUse = Math.max(scrWidth / widthIn, scrHeight / heightIn);
scrDoc.resizeImage(undefined, undefined, resUse, ResampleMethod.NONE);

// Destination folder for the resulting file
var destinationFolderPath = "/Volumes/Epefany/Collections/Majestic Mosaics/WallArtMock/";
var destinationFileName = "resulting_file.psd";
var destinationFilePath = destinationFolderPath + destinationFileName;
scrDoc.saveAs(new File(destinationFilePath));

var temp_SO = new File(destinationFilePath);
scrDoc.close(SaveOptions.DONOTSAVECHANGES);

replaceSO(temp_SO);
temp_SO.remove();
} else {
alert('The current layer is not a Smart Object.');
}

function replaceSO(file) {
var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
var desc866 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc866.putPath(idnull, new File(file));
var idPgNm = charIDToTypeID("PgNm");
desc866.putInteger(idPgNm, 1);
executeAction(idplacedLayerReplaceContents, desc866, DialogModes.NO);
}
1
  • 1
    Hi Patrice and welcome to GDSE. The script you shared looks a bit like a frankenstein’s monster and to make it work like you want it should be rewritten. I think your question is rather a job description then a real question so I’m voting to close it. By the way did you by any chance used Chatgpt to edit the question you originally wrote? Jun 1, 2023 at 9:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.