Skip to main content
Kmeanskeshav
Participating Frequently
April 5, 2017
Answered

RePlace My Design In All Mockups SmartObjects

  • April 5, 2017
  • 1 reply
  • 5930 views

I HAVE 100 + MOCKUPS AND WANT TO CHANGE MY DESIGN IN ALL MOCKUPS I ADD DESIGN AND 2 MOCKUPS PLEASE HELP

1st mockup : 1+3 t.psd - Google Drive

2st mockup : Apple Iphone 6 6s.psd - Google Drive

Image : Black-Gold-Marbel-Unisex-Design.psd - Google Driv...

These are 2 mockups  and one psd i have multiple mockup like this 100+ i want to do changes in all mockup with this image

This topic has been closed for replies.
Correct answer c.pfaffenbichler

// select folder of mock-ups, if they contain exactly one smart object replace its content with selected designs and save jpg-files;

// 2017, use it at your own risk;

#target photoshop

var theFolder = Folder.selectDialog ("select folder");

if (theFolder) {

var theFiles = theFolder.getFiles(/\.(psb|tif|psd)$/i);

if (theFiles.length > 0) {

//var theDesigns = theFolder.getFiles(/\.(psb|jpg|tif|psd)$/i);

// select files;

if ($.os.search(/windows/i) != -1) {var theDesigns = File.openDialog ("please select files", "*.psd;*.psb;*.tif", true)}

else {var theDesigns = File.openDialog ("please select files", getFiles, true)};

if (theDesigns.length > 0) {

for (var x = 0; x < theFiles.length; x++) {

replaceSmartObject(theFiles, theDesigns);

}

}

}

};

////// replace smart object content if only one smart object exists //////

function replaceSmartObject (theFile, theDesigns) {

var myDocument = app.open(theFile);

var theSmartObjects = collectSmartObjects();

// if only one smart object;

if (theSmartObjects.length == 1) {

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = theSmartObjects[0][0];

myDocument.activeLayer = theLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// jpg options;

var jpegOptions = new JPEGSaveOptions();

jpegOptions.quality = 9;

jpegOptions.embedColorProfile = true;

jpegOptions.matte = MatteType.NONE;

// work through the array;

for (var m = 0; m < theDesigns.length; m++) {

// replace smart object;

theLayer = replaceContents (theDesigns, theLayer);

var theNewName = theDesigns.name.match(/(.*)\.[^\.]+$/)[1];

//save jpg;

myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".jpg")),jpegOptions,true);

}

};

myDocument.close();

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

if (theFile.name.match(/\.(psd|tif|psb)$/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

};

////// select smart objects, based on paul riggott’s code //////

function collectSmartObjects(){

var theSmartObjects = new Array;

if(!documents.length) {return};

selectAllLayers();

var selectedLayers = getSelectedLayersIdx();

for(var a = 0; a < selectedLayers.length; a++){

if(hasSmartObject(Number(selectedLayers))){

makeActiveByIndex(Number(selectedLayers),false);

theSmartObjects.push([app.activeDocument.activeLayer, a])

}

};

return theSmartObjects;

function hasSmartObject(idx){

var ref = new ActionReference();

ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( "smartObject" ));

ref.putIndex( charIDToTypeID( "Lyr " ), idx);

var desc = executeActionGet(ref);

if(desc.hasKey(stringIDToTypeID('smartObject'))) {return true}

else {return false};

};

function makeActiveByIndex( idx, visible ){

    var desc = new ActionDescriptor();

      var ref = new ActionReference();

      ref.putIndex(charIDToTypeID( "Lyr " ), idx);

      desc.putReference( charIDToTypeID( "null" ), ref );

      desc.putBoolean( charIDToTypeID( "MkVs" ), visible );

   executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

};

function getSelectedLayersIdx(){

  var selectedLayers = new Array;

  var ref = new ActionReference();

  ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

  var desc = executeActionGet(ref);

  if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

  desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

  var c = desc.count;

  var selectedLayers = new Array();

  for(var i=0;i<c;i++){

  try{

  activeDocument.backgroundLayer;

  selectedLayers.push(  desc.getReference( i ).getIndex() );

  }catch(e){

  selectedLayers.push(  desc.getReference( i ).getIndex()+1 );

  }

  }

  }else{

  var ref = new ActionReference();

  ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

  ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

  try{

  activeDocument.backgroundLayer;

  selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

  }catch(e){

  selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

  };

  };

  return selectedLayers;

};

function selectAllLayers() {

var desc29 = new ActionDescriptor();

  var ref23 = new ActionReference();

  ref23.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

desc29.putReference( charIDToTypeID('null'), ref23 );

executeAction( stringIDToTypeID('selectAllLayers'), desc29, DialogModes.NO );

};

};

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
April 9, 2017

// select folder of mock-ups, if they contain exactly one smart object replace its content with selected designs and save jpg-files;

// 2017, use it at your own risk;

#target photoshop

var theFolder = Folder.selectDialog ("select folder");

if (theFolder) {

var theFiles = theFolder.getFiles(/\.(psb|tif|psd)$/i);

if (theFiles.length > 0) {

//var theDesigns = theFolder.getFiles(/\.(psb|jpg|tif|psd)$/i);

// select files;

if ($.os.search(/windows/i) != -1) {var theDesigns = File.openDialog ("please select files", "*.psd;*.psb;*.tif", true)}

else {var theDesigns = File.openDialog ("please select files", getFiles, true)};

if (theDesigns.length > 0) {

for (var x = 0; x < theFiles.length; x++) {

replaceSmartObject(theFiles, theDesigns);

}

}

}

};

////// replace smart object content if only one smart object exists //////

function replaceSmartObject (theFile, theDesigns) {

var myDocument = app.open(theFile);

var theSmartObjects = collectSmartObjects();

// if only one smart object;

if (theSmartObjects.length == 1) {

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = theSmartObjects[0][0];

myDocument.activeLayer = theLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// jpg options;

var jpegOptions = new JPEGSaveOptions();

jpegOptions.quality = 9;

jpegOptions.embedColorProfile = true;

jpegOptions.matte = MatteType.NONE;

// work through the array;

for (var m = 0; m < theDesigns.length; m++) {

// replace smart object;

theLayer = replaceContents (theDesigns, theLayer);

var theNewName = theDesigns.name.match(/(.*)\.[^\.]+$/)[1];

//save jpg;

myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".jpg")),jpegOptions,true);

}

};

myDocument.close();

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

if (theFile.name.match(/\.(psd|tif|psb)$/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

};

////// select smart objects, based on paul riggott’s code //////

function collectSmartObjects(){

var theSmartObjects = new Array;

if(!documents.length) {return};

selectAllLayers();

var selectedLayers = getSelectedLayersIdx();

for(var a = 0; a < selectedLayers.length; a++){

if(hasSmartObject(Number(selectedLayers))){

makeActiveByIndex(Number(selectedLayers),false);

theSmartObjects.push([app.activeDocument.activeLayer, a])

}

};

return theSmartObjects;

function hasSmartObject(idx){

var ref = new ActionReference();

ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( "smartObject" ));

ref.putIndex( charIDToTypeID( "Lyr " ), idx);

var desc = executeActionGet(ref);

if(desc.hasKey(stringIDToTypeID('smartObject'))) {return true}

else {return false};

};

function makeActiveByIndex( idx, visible ){

    var desc = new ActionDescriptor();

      var ref = new ActionReference();

      ref.putIndex(charIDToTypeID( "Lyr " ), idx);

      desc.putReference( charIDToTypeID( "null" ), ref );

      desc.putBoolean( charIDToTypeID( "MkVs" ), visible );

   executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

};

function getSelectedLayersIdx(){

  var selectedLayers = new Array;

  var ref = new ActionReference();

  ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

  var desc = executeActionGet(ref);

  if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

  desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

  var c = desc.count;

  var selectedLayers = new Array();

  for(var i=0;i<c;i++){

  try{

  activeDocument.backgroundLayer;

  selectedLayers.push(  desc.getReference( i ).getIndex() );

  }catch(e){

  selectedLayers.push(  desc.getReference( i ).getIndex()+1 );

  }

  }

  }else{

  var ref = new ActionReference();

  ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

  ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

  try{

  activeDocument.backgroundLayer;

  selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

  }catch(e){

  selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

  };

  };

  return selectedLayers;

};

function selectAllLayers() {

var desc29 = new ActionDescriptor();

  var ref23 = new ActionReference();

  ref23.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

desc29.putReference( charIDToTypeID('null'), ref23 );

executeAction( stringIDToTypeID('selectAllLayers'), desc29, DialogModes.NO );

};

};

Kmeanskeshav
Participating Frequently
April 16, 2017

its working fine but ever time popup comes that please close or save

c.pfaffenbichler
Community Expert
Community Expert
July 16, 2017

and how can i change Am Code ???


and how can i change Am Code ???

You can record AM code with ScriptingListener.plugin