Copy link to clipboard
Copied
I am using the following script, but would like to edit multiple smart objectives within my mockup template file. Basically my template file has a desk coaster and a mouse pad. The issue is that my image files will be different sizes. Is there a way to modify the script or another automated process to develop the mouse pad & coaster with the same image?
// Replace SmartObject’s Content and Save as JPG
// 2017, use it at your own risk
// Via @circle 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 = 11;
// 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", "*.png;*.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[m], theLayer);
var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
// Save JPG
myDocument.saveAs((new File(thePath + "/" + theNewName + ".jpg")), jpgSaveOptions, true,Extension.LOWERCASE);
}
}
}
};
// Get PSDs, TIFs and JPGs from files
function getFiles(theFile) {
if (theFile.name.match(/\.(png|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
};
//Alert Letting the User Know the Script Has Finished
alert("Finished!\nThe script has finished saving the jpeg thumbnails in the folder with the original mockup");
Copy link to clipboard
Copied
Perhaps one of these scripts can help:
http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html
If you search the forum you will also find many other SO replacement scripts.
Good luck!
Copy link to clipboard
Copied
Hey @Stephen_A_Marsh I searched the forums on replacing multiple SO scripts within one mockup. I have previously browsed and attempted to use the PHoto Collage Tool Kit pack, but was not successful. If you could point me to some threads on replacing multiple SO scripts I would be be very thankful!
Copy link to clipboard
Copied
@lido240674372bja wrote:
I have previously browsed and attempted to use the PHoto Collage Tool Kit pack, but was not successful.
Why weren't you successful? Did you follow the 4 rules?
There are three scripts that may possibly be suitable:
BatchUpdateSmartObject.jsx - Used to populate simple Mockup templates like BatchReplaceOneObject script but can update more than a single smart object layer.
BatchMockupTemplates.jsx - Used to populate multiple Mockup Templates that needs to be populated with the same replacement image objects.
PopulateAlbumPageMockups.jsx - Used to populate a collection of Photo Page Mockup templates for a Picture Album.
Copy link to clipboard
Copied
I attempted to use BatchUpdateSmartObject.
The issue was it was only replacing one smart object.
Simple Mockup Template File Structure:
Objects Collection Folder Had 2 Subfolders named obj0 & obj1
Output is desktop and selection is edit smart objects.
The script is only editing the top level SO and saving. I'm not sure what I'm doing wrong. Both obj subfolders have the exact same number of images.
Copy link to clipboard
Copied
Export top SO's, then link both SO's to exported content and change them to embedded.
Copy link to clipboard
Copied
Are you saying to run the original script and save each one as PDF and manually go through each mock up to save singular design?
Copy link to clipboard
Copied
No. You export content of Smart Objects by Layers panel contextual menu.
After you link them all singly to the same file, they'll contain same content.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Didn't you look solution for: "The issue was it was only replacing one smart object."?
Copy link to clipboard
Copied
Please provide meaningful screenshots to illustrate the Layer and file-structure.
Copy link to clipboard
Copied
Thanks for your assistance. See below
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That screenshot seems to illustrate neither.
Please provide a meaningful description, including screenshots, of the intended process.
Will there be two files for the two different crops of the switch-in-image, will the two Smart Objects contain Smart Objects of the same image to create the two crops, …?
Copy link to clipboard
Copied
I would like to drop in two images of the same image to replace the SO of the coaster and desk set. The current script calls only the selected SO to be replaced and saved.
Copy link to clipboard
Copied
Your explanations and screenshot-snippets seem insufficient to me.
Good luck!
Copy link to clipboard
Copied
As far as getting the replaced smart object images to be the same size, as the original image, you can try the script on this link: