Skip to main content
Known Participant
June 22, 2021
Answered

Batch Mockup Multiple Dimensions

  • June 22, 2021
  • 4 replies
  • 4414 views

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.

 

 

This topic has been closed for replies.
Correct answer c.pfaffenbichler
Looks like i need to work on my english.

https://we.tl/t-dzoEO58yJi

Please ask me anything if you need further information about proccess.

Thank you for helping me again.

 


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 = openSmartObject();
        for (var m = 0; m < theFiles.length; m++) {
            var thisOne = theFiles[m];
            replaceContents (thisOne, theSO.activeLayer);
            theSO.save();
            activeDocument = myDocument;
            saveJpg(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 saveJpg (thePath, theName, theNewName) {
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg;
activeDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".jpg")),jpegOptions,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); 
    }
    };

 

4 replies

akmia51
Inspiring
July 28, 2022

 

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

 

 

Abdul karim mia
PECourtejoie
Community Expert
Community Expert
September 7, 2021

Hello, I have to commend Christoph and JJ here, as they provide tremendous free help for what seems to be a commercial endeavour...

JJMack
Community Expert
Community Expert
July 3, 2021

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.

 

 

JJMack
JJMack
Community Expert
Community Expert
July 4, 2021

I did find a Free 3D Coffee Mug model I can batch populate in Photoshop

JJMack
Known Participant
July 4, 2021

Can you share a guide so i can use it. It looks aweasome

c.pfaffenbichler
Community Expert
Community Expert
June 22, 2021
Your process seems more complicated that strictly necessary, a Smart Object within a Smart Object should allow to switch in content with »Replace Contents« fairly easily while avoiding the Selection and aligning. 
 
As for the automation-part  have you done a Forum serch fro mock-up scripts? 
Known Participant
June 22, 2021

Yes did that mr JJmack has script file for batching mockups but i cant make it work for some reason

c.pfaffenbichler
Community Expert
Community Expert
June 22, 2021

Please post a link to the Script (or the Script itself). 

 

How are you setting up the operation? Manual selection of the new file/s, folder of files, …?