Mobile app version of vmapp.org
Login or Join
Carla748

: Replacing a smart object in bulk with Photoshop's variable data or scripts Is there a way to automate the replacement of a Smart Image with a different graphic? For example, if I have a master

@Carla748

Posted in: #AdobePhotoshop #PhotoshopScripting #Script #Smartobject

Is there a way to automate the replacement of a Smart Image with a different graphic?

For example, if I have a master image of a mug, and a large number of flat rectangular images/designs I'd like on the mug, after some processing. I've set up a smart image using one of the designs and I've tweaked it with some filters to make it less rectangular (adjusting the perspective, bending the top and bottom to match the curve of the mug, etc.).

Now I need to figure out how to use Variables (if possible) to replace the image in the Smart Object so the same transformations/filters will be run on each image, which will then be placed on the mug and saved.

I see this tutorial which explains the basics of Variable data and shows how to use images as data -- but it's not clear to me how to use this to update the Smart Object so that all the transformations get applied to the images.

If Variables won't work with Smart Objects, I'm also open to using a script. (I'd love a snippet on how to update a smart object via script if anyone has one, as I've never used scripts with Photoshop before).

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Carla748

2 Comments

Sorted by latest first Latest Oldest Best

 

@Murphy569

I found this page that has an answer that looked close to what you're looking for, I modified it to work with the latest version and to hopefully fit your needs better.

Here's how to use it:


Save the code below in a file with a .js extension
Open your template file and select the SmartObject
Go to File->Scripts->Browse
Find your .js file and open it
Select your images/designs and open them
You're done!


.js file contents:

// Replace SmartObject’s Content and Save as PSD
// 2017, use it at your own risk #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;
// PSD Options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
psdOpts.spotColors = true;
// 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[m], theLayer);
var theNewName = theFiles[m].name.match(/(.*).[^.]+$/)[1];
// Save JPG
myDocument.saveAs((new File(thePath + "/" + theName + "_" + theNewName + ".psd")), psdOpts, true);
}
}
}
};
// 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
};

10% popularity Vote Up Vote Down


 

@Odierno310

open the mug PSD keep the mug layer below the image you want and you can import all the images you want on the mug and record actions for the perspective adjustments.and play those actions on every layer which contains the image you want on the mug. you can convert all the images to smart objects either using actions or by just doing it manually it will just take two clicks. you can also assign a function key for the action you recorded so that you can just press a button and the output will be put into the folder you selected while recording the action. this should make it one button press job if not complete Automation. but that's the closest you can get without having to code. if you still seek complete automation you will have to write some code.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme