Copy link to clipboard
Copied
Greetings,
Unfortunately, my scripting knowledge is very minimal. In using this script, the script times out and no output files occur. I am on a pc running Photoshop CC (online subscription, latest update). It was suggested to me by another forum member to start a new discussion thread here to assist with this problem.
This is what I have:
This is what I would like a script to do (if possible):
We have over 50k of mockups to do for this particular canvas shape/size....
Any suggestions on how I could streamline this process without having to manually replace and save? THANK YOU!!!
// replace smart object’s content and save psd; |
// 2011, 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 smart object; |
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) { |
// work through the array; |
for (var m = 0; m < theFiles.length; m++) { |
// replace smart object; |
theLayer = replaceContents (theFiles |
var theNewName = theFiles |
//Raise color picker for Back cover; |
try { |
app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1]; |
// ======================================================= |
var idsetd = charIDToTypeID( "setd" ); |
var desc7 = new ActionDescriptor(); |
var idnull = charIDToTypeID( "null" ); |
var ref2 = new ActionReference(); |
var idcontentLayer = stringIDToTypeID( "contentLayer" ); |
var idOrdn = charIDToTypeID( "Ordn" ); |
var idTrgt = charIDToTypeID( "Trgt" ); |
ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt ); |
desc7.putReference( idnull, ref2 ); |
var idT = charIDToTypeID( "T " ); |
var desc8 = new ActionDescriptor(); |
var idClr = charIDToTypeID( "Clr " ); |
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" ); |
desc7.putObject( idT, idsolidColorLayer, desc8 ); |
executeAction( idsetd, desc7, DialogModes.ALL ); |
} catch (e) {}; |
//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 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 |
}; |
thank you JJMack !!
this script is working great now! Here is the final working script:
// replace smart object’s content and save psd;
// 2011, 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
...Copy link to clipboard
Copied
How are you running that script. The script is designed to be run with an open layered document that you target that is a smart object layer you that want to replace its content. Once you target that smart object layer you run the script. The script should open an Open Files dialog for you to select the image files you want to use as replacement images. The image file types can be PSD, Tif and Jpeg. The script will then replace the smart object layer object's with the images and save PSD files not jpeg files in the same folder as the open document you run the script on. It also try to do something about a back cover so the open document must have some other layer that is a back cover.
If you have 50K mockup you would need to open them one at a time target a smart object layer run the script, select the replacement images files. You have a lot of work to do. You could easily change the script to so all you would need to do is select the folder containing your replacement images and save Jpeg files not PSD file. Still you would need to open 50K image files one at a time target the smart object layer and select a folder of image files.
When you want to Process 50,000 mockup files you do not want to need that much human interaction you would want to automate the process of targeting the smart object layer and selecting the folders that contain the proper set of replacement images for each mockup. You would want to batch process your mockup not have to run 50,000 mockup jobs to populate your mockups. You need to design a mockup template design that can be batch populated. The develop the batch populating process and script it.
Copy link to clipboard
Copied
Thank you for your detailed response. Please let me clarify what this project entails.
1 PSD Mockup file (layered, with a Smart Object layer)
50k replacement image files
I removed the section of code that contained "the back cover" layer as it was not needed. After some trial and errors, the script began to work well.
How can the script be modified so it saves the final output as a jpg (not psd)?
// replace smart object’s content and save psd;
// 2011, 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 smart object;
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) {
// work through the array;
for (var m = 0; m < theFiles.length; m++) {
// replace smart object;
theLayer = replaceContents(theFiles
var theNewName = theFiles
//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 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
};
Copy link to clipboard
Copied
Change the psd save options section to a save jpeg options section and change the save statement to save as jpeg file with the jpeg filename not psd and use save option you changed the psd save options to. You will still need to navigate to the replacement images folder and select all the files.
Copy link to clipboard
Copied
I know this is an old thred but I am desperatly searching for an answer to the above but for Mac OX. I am trying to find a script to do the same action as mpspringer where I ahve one mockup which I want to save multiple times with different replacments images. Do any of you know how to do on a mac?
L.seger
Copy link to clipboard
Copied
Post your mockup PSD....
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks for your reply JJMack, I just posted two screenshots above of the psd file. I dont belive there is anything wrong with the file itself, I have variable psd files with smart layers which I intend to use. My question relates more how to implicate a code into a script and get that working with my PS. Just to keep things easu and simple I purchased an extention from Adobe Exange Market Place (See screenshot) for Batach smart layer replacement but it did not even instal correctly. I dont care about this app/extention to much, would be happy unistall it. I would love to get help with how to get a script working and then I dont need to worry about the app. I am in a simillar position as mpspringer with a very high numbers of files to process, also it non profitable so it would be great to keep the time of workflow to a minimal. I run latest photoshop on my Macbook and Mac mini
l.seger
Copy link to clipboard
Copied
That Mockup is populated with your Design by replacing the contents of the Smart Object in the template. You do this in one of two ways. You can use menu Layer>Smart Objects> replace content or open the bar object for edit and edit your replacement into the object. If you use replace content all replacement image are required tie be exactly the same as the object in the template. Their Canvas Size, Aspect Ratio and Print resolution need to mate the smart object exactly. For the Smart Object layers associated Object Transform is not replaced when the object is replaced. If you edit the Object you can use any size image but you must resize any mismatch to fill the smart object canvas. Your object has a landscape Aspect ratio. For best results the replacement images should have a landscape aspect ratio close to the aspect ratio the smart object has. You see the Mockup has a second Smart object layer that share the same object as the top Smart Object layer has. Its Associated Object Transfer distort the object to the perspective you see in the mockup.
"I have variable psd files with smart layers which I intend to use" I do not know what you mean by that Photoshop Data driven Grapics can only toggle the visibility of smart object layers it can not replace the layers content.
That extension you bough may be able to do what your replacements are all exactly like the object in the mock. I was not about to pay for something I do not need. My Free Mocup scripts can replace smart object layer content via Replace content or Edit. Content. The scripts by default will use replace Content. However, they have an Edit option and additional edit options,
Photo Collage and Mockup Toolkit
Copy link to clipboard
Copied
Many thaks gain for your time on this JJMack. I have fairly long experince with aspect ratio and sizes so all that make sense to me, what I am after is a batch / automation to replace the smart object in this psd with a large amount of different jpgs from a selected folder and then to be saved in an other folder automatically, all to save vast amout of time.
"I have variable psd files with smart layers which I intend to use"
This was just a sidetrack saying that I have more psd files with smart objects which I intend to use as well as the one I have shown you. However they have all same structure, just different content.
Thanks for your opinion about paying for things, I share your opinion complelty as I am a self employed low income induvidul, I just desperetly tried to keep things easy as well support someone else, but I had to bite the bullet in the end. If possible I would love to get your help with getting an automated "batch action" to replace smart objects.
l.seger
Copy link to clipboard
Copied
My scripts using the edit option will fit any image to the smart object. Landscape image will work best. Again I have no idea of what you mean by. ""I have variable psd files with smart layers which I intend to use". Any image size can be used the mockup psd does not need to be changed have a defined variable.
Here I populated three mockup templates. Two have Portrait smart object one has a Language smart object. I through replacement image at them some Landscape some portrait some jpeg files one RAW file an one psd file. I use my Script.s Edit option and let the script fit the images as centered aspect ratio selections.
Copy link to clipboard
Copied
That looks amazing, how do I get this to work with my PS on my Mac?
l.Seger
Copy link to clipboard
Copied
My scripts are written in javascripts I tried I tried to code them to work on both platforms. However, I no longer have access to a Mac I have not been able to test my scripts on a Mac in years. Try installing my package. I know the locations for Scripts and layer styles etc deffer between platforms. They are free it only going to take some of your time. They may save you much time.
Copy link to clipboard
Copied
I can confirm with you JJMack that your script is running fine on in PS on my Mac (10.15.4).
I have only tried to run the "Batch Replace One Object" script so far and it is smooth and works perfectly. I know love scripts more than anything else and want to learn more .
Many Thanks again for your time with this
Very Best
L.Seger
Copy link to clipboard
Copied
That was the first mockup script I wrote. Then I updated it to be able to populate more than one smart object layer Then I update that script to be able to populate more than one template. So BatchMockupTemplates.jsx can do it all. The other two scripts BatchReplaceOneObject.jsx and BatchUpdateSmartObject.jsx
Copy link to clipboard
Copied
Ah I see, I dint understand the difference between them at first.
I can't get these ones to work though, please see screen shots for the error messages. Just to let you know that the folders stated missing are not missing. I have deleted them and created new ones but not working at all.
Copy link to clipboard
Copied
To be able to populate more than one smart object layer and keep the script simple. I needed a design the that you would be able to have a collection of replacement for each smart object layer on the top of the layers stack. To keep the scripts dialog basically the same the folder for the replacement images was change to a collection of sub folder with a particular name. obj0, obj1, obj2,... obj n, Where image in obj0 would be populated into the topmost smart object layer, obj1 the next smart object layer down etc. The output Mockup file names is still composed from File name in obj0, Also all the obj sub folder need to have exactly the same number of replacement images. If you are batching multiple templates the templates need not all have the same number of smart object layers to be replaced. However, the collection of replacement images must have the number of obj(n) folder for the template with the most smart object layers that need to be populated. This is in the documentation. Its brief for I can not type. The image are process in file name sort order. The replacement image need to sore in the order you want . I leading sequence number can the added so image will be populate correctly otherwise the population will be random.
The message you are getting shows you did not create the collection of sub folders. If you are populating only one smart object layer theere still needs to be an obj0 sub folder for populating the top most smart object layer.
To script Photoshop you need to develop some programming skills, know how Photoshop works well and be able Design process for automating what you want done. You need to have a well thought out design before you start coding. You need to design for all things that can possibility happen or your script will have too many restriction, dependencies and bugs.
Copy link to clipboard
Copied
If you think about it. The first script of mine you used to replace one smart object is very simple and easy. It is also the basics for the other two scripts.
For the single smart object you pointed the script to a template, to a sequences of replacement images. And a folder to store the populated jpeg images. The script would open the template and replace the content of the object with an replacement and saved a jpeg, repeat the replace step and save step till all replacements were done then terminate.
The complexity come in the the replace step. If the script uses replace content all the replacement image need to be the same size, aspect ratio and have the same print resolution. However, there is an alternative way to replace and object's contents that is the Object can be edited and its content altered. This add extra complexity for all possible object would not be edited by Photoshop. If a template's smart object is a placed RAW file or a AI vector file like .svg or .ai. The object would be edited by ACR or AI not Photoshop. So the replace step, if edit option is used can not handle smart object layers that object would not be edited by Photoshop. These layers will not be replace you will be informed of this and you should re-work the template if you want to use the edit option to be able to use any size image.
So the simple replace object became a complex step. Still the overall design is simplistic. The script hast no Idea about the content of replacements no matching is done the replacements are just processed in file name sort order.
To user this in a script and be able to process more than one smart object layer there would need to be a que of replacement object for each smart object layer to be replaced. The ques locations need to have a known folder location for the smart object stack order the sub folders obj0,.....objn. Again no matching is gone the images need to sort so they will populate with the image in the other ques correctly. The script just process the folders in file name sort order. The only change to the script dialog is the replacement image ques became a collection of cues via the sub folder the user needs to populate with imaged for each smart object layer. The sub folders name are required to be obj0, obj1, .... objn. The Replace step was repeated till all the smart object layers in the template were replaced before the jpeg file was saved. The first script became part of a loop. The third script the second script became part of a loop. The dialog was changed to point to a que of templates to be populated.
Copy link to clipboard
Copied
This is really intresting, thank you so so much for sharing. Last question, do you have a youtube channel or similar where all your script is in action or showcased?
Best
L.Seger
Copy link to clipboard
Copied
Over the years I made some things available, Some are junk some outdated. Some broken by Adobe Photoshop Updates. All may be useful if someone read how they work. They may learn how I did thing and get a better understanding of how Photoshop works. There are all still available from my web page. Crating actions has quite a bit of good information and contains a dozen or more scripts I wrote to be used in Photoshop Actions to help actions the be able to do sometthing that require the use of logic. Unfortunately Adobe broke the run twice scripts they add a bug into Photoshop scripting . The scripts can no longer remove their data from the document's meta data field info if removing the data would result in returning the field back to its original empty state. I After CC 2015.5 I simply add a new document and an open document event to the script event manager the adds "Garbage" into the info field if its not there. My scripts have no problem returning the field back to Garbage. The Place watermark script can be useful for some as can the Collage and Mockup Toolkit IMO.
Here is my web page Photoshop Packages Developed by JJMack
one of my collage scripts in action.
Copy link to clipboard
Copied
JJMack I made an account specifically to thank you! These scripts were lifesavers for me. I spent a good 2 hours trying to manually use photoshop's scripts for 4 different processies till i sought help. Wish i ran across this sooner! You're the man!!!!!
Copy link to clipboard
Copied
Nice to hear you found them and they are useful for you makes me feel good.
Copy link to clipboard
Copied
JJMack, you've just saved me an insurmountable amount of time with your scripts... You are truly a gem. Thank you so much I'm really grateful for your help!
Copy link to clipboard
Copied
Hello JJMack,
1st of all thanks a lot for that awesome scripts. Currently I'm using the Photoshop Bacth Mockup script. I need some help with that script. I want to do,
I'm mostly working with book mockups so,
1. The image of book should resize according to the canvas automatically & entirely. If I use fit image it doesn't resize to fix frame. As you can see in the picture, it leaves white background in the front and also
just get fixed on the spine
But I want it be be like this
2. It only work with Top layer & then second or third layer. Is there any possible way so that it can work with any smart object layer?
Thanks a lot!
Rahat.
Copy link to clipboard
Copied
I keeo getting a error message for line 30. I am usinhg a mac a photoshop cc. Can you help with that? Please?!