Copy link to clipboard
Copied
Hello i got a mockup file like this. Im trying to batch process my designs with this mockup.
I archive my designs like this
i want to write script to crop my pdf file like
and place it into smart layer
fit to canvas and align to right
Save smart object layer . psd so mockup generates photo
save this file photoname-mockup-righthand.jpeg
select all layers than flip horizontal
edit smart object layer
select all layers than flip horizontal
select all layers and align it to left.
save smart object psd so mockup generates new photo
save this file photoname-mockup-lefthand.jpeg
Can anyone help me to write script to batch process my designs to mockup photos.
I have no javascript knowledge*
Sorry for my bad english.
Thank you.
With below code I get these resulting images for »Mug Right.psd«:
// 2020, use it at your own risk;
if (app.documents.length > 0) {main()};
function main () {
try {
var myDocument = activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theFiles = selectFile (true);
var theLayers = collectLayersByName ("Your Design Here");
selectLayerByID(theLayers[0][2],false);
var theSO = openSmar
...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I have no idea of what pdf save option you want to use. Something like this may save a pdf with default options.
function SavePDF(thePath, theName, theNewName){
saveFile = new File(thePath + "/" + theName + "_" + theNewName + ".pdf");
pdfSaveOptions = new PDFSaveOptions();
activeDocument.saveAs(saveFile, pdfSaveOptions, true, Extension.LOWERCASE);
};
Copy link to clipboard
Copied
Compression => None
Embed Page Thumbnails
Optimize for fast web preview
Thank you so much
Copy link to clipboard
Copied
These are the options that are documented set those you want to use.
Copy link to clipboard
Copied
// 2020, use it at your own risk;
if (app.documents.length > 0) {main()};
function main () {
try {
var myDocument = activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theFiles = selectFile (true);
var theLayers = collectLayersByName ("Your Design Here");
selectLayerByID(theLayers[0][2],false);
var theSO = openSmartObject();
for (var m = 0; m < theFiles.length; m++) {
var thisOne = theFiles[m];
replaceContents (thisOne, theSO.activeLayer);
theSO.save();
activeDocument = myDocument;
savePDF(thePath, theName, new File (thisOne).name.match(/(.*)\.[^\.]+$/)[1]);
activeDocument = theSO;
};
theSO.close();
}
catch (e) {alert ("something is wrong")}
};
////// open smart object //////
function openSmartObject () {
var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
var desc2 = new ActionDescriptor();
executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );
return activeDocument;
};
////// 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
};
////// select files //////
function selectFile (multi) {
if (multi == true) {var theString = "please select files"}
else {var theString = "please select one file"};
if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.pdf;*.ai', multi)}
else {var theFiles = File.openDialog (theString, getFiles, multi)};
////// filter files for mac //////
function getFiles (theFile) {
if (theFile.name.match(/\.(jpg|tif|psd|pdf|ai)$/i) || theFile.constructor.name == "Folder") {
return true
};
};
return theFiles
};
////// save a jpg //////
function SavePDF(thePath, theName, theNewName){
saveFile = new File(thePath + "/" + theName + "_" + theNewName + ".pdf");
pdfSaveOptions = new PDFSaveOptions();
activeDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".pdf")),pdfSaveOptions,true);
};
////// collect layers with certain name //////
function collectLayersByName (aName) {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
if (theName == aName) {theLayers.push([theName, theIndex, theID])}
};
}
catch (e) {};
};
return theLayers
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
Could anyone help me fix this code ? it does not work. manually changed jpeg save options to pdf. For some reason it crashes photoshop.
Copy link to clipboard
Copied
You need to run it in a debugger so you can see what line fails. This script does several things. What have you tried ths far for troubleshooting?
Copy link to clipboard
Copied
I see no crash I get an erroe for there is no savePDF function. I the scipt I see line 17
savePDF(thePath, theName, new File (thisOne).name.match(/(.*)\.[^\.]+$/)[1]);
But in the script I see a function
function SavePDF(thePath, theName, theNewName){
There is also a problen with line 14 I had to comment out that line
replaceContents (thisOne, theSO.activeLayer);
you opened the smart object file for edit if it was a Photoshop object. The Active in the open smart object is more likely not a Smart Object layer that cans have its contents replace. The Replace content statement will fail for replace content is not available for the activate layer type in the object file You would edited the selected files onto the object. If you want to repeatedly replace the smart object do not open the smart object replace its content.
If you look at my mockup populating script you wile see both ways to update smart object, Replace content require the replacement file to be the correct size replacements. Where if the replacement are not the correct size the script can open the objects and edit the replacement file into the object file document when the object is saved Photoshop will replace the content of the smart object in the template.
You also need to look before you use openSmartObject For if the Smart object is a RAW or Vector Object. the The object will open in ACR or AI your script will not be able to edit the object.
Copy link to clipboard
Copied
I looked for a free Coffee Mug 3D nodel that you may bat ablet to coat the surface with a design like your london panorama.
All the ones I found outer surfaces uv were complex. It would not be easy to place a panaramra images onto the cups outer surface.
Copy link to clipboard
Copied
I did find a Free 3D Coffee Mug model I can batch populate in Photoshop
Copy link to clipboard
Copied
Can you share a guide so i can use it. It looks aweasome
Copy link to clipboard
Copied
I'm not completely happy with the model for the way the model works the surface seems to needs a distorted image that has been stretched tall when it applied 3D feature distorted it back down. The script I wrote just replaces top surface in a 3D layer named 3Dtexture. I have never made the script public, There are also Issues in Photoshop 2021 3D the models does not work properly I just try to close the document Photoshop 22.4.2 terminates unexpectedly. I have to use Photoshop 2020 version 21.2.9. 3D models surfaces can be complex and the UV fold out all over the canvas. I have only used easy geometric models the Surface have flat areas I populated with images. I create Photo Collage or Mockup templates and use my batch populating scripts to populate these templates to create replacement surfaces for the 3D model template. So its two batch Jobs to populate the 3D templates which also has a video time line the script save a populated PSD and an MP4 video and optionally a jpeg.
https://www.turbosquid.com/Download/457218_2811792
So it a complex process. The 3D template is complex to create and you also need to create a collage or mockup template to build surfaces for the 3D template.
Copy link to clipboard
Copied
Hello, I have to commend Christoph and JJ here, as they provide tremendous free help for what seems to be a commercial endeavour...
Copy link to clipboard
Copied
Now Using Bulk Mockups Filler, Automatically Replace Smart Object Content Perfectly in Any Adobe Photoshop Version.
Unlimited Mockups at a time
Unlimited Design image at a time
4 Resizing Options
6 Alignment Options
3 Output Options (PSD, JPG, PNG)
Auto Output Folder By Template Name
Auto Output Folder By Save Option
bulkmockupsfiller . Com
Find more inspiration, events, and resources on the new Adobe Community
Explore Now