• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

RePlace My Design In All Mockups SmartObjects

New Here ,
Apr 05, 2017 Apr 05, 2017

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

5.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 09, 2017 Apr 09, 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 fil

...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 09, 2017 Apr 09, 2017

Copy link to clipboard

Copied

// 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 );

};

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 16, 2017 Apr 16, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2017 Apr 16, 2017

Copy link to clipboard

Copied

If you are certain the files were not open before running the Script and therefore might contain unsaved changes you could change the line

myDocument.close()

to

myDocument.close(SaveOptions.DONOTSAVECHANGES)

Good luck!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 16, 2017 Apr 16, 2017

Copy link to clipboard

Copied

Ohk Thankyou So much My Friend For Your Help Hope Once Day I Will Learn Coading And Help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

Hello Maa Friend

Is There Is any why to make it faster

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

That may well be ā€¦

Generally AM code is faster than DOM code so you could try replacing the saving portion with AM code.

The function Ā»collectSmartObjectsĀ« also might be improved in that regard.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

Ohk Sure

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

Hie C.pfaffenbichler I Have One Question When This Script get or open mocups from the folder i want it should ger mockups from the subfolders also so that diffrent diffrent images not mix How Can i change this portion of script

// 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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

This Script get or open mocups from the folder i want it should ger mockups from the subfolders also so that diffrent diffrent images not mix

What exactly do you mean?

Please post screenshots clarifying the File/Folder-structure and the results you want to get.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

Like Now I Have To Put All Mockups in One Folder i Have 10  Different Category Mockups I Want To Put ALL MOCKUPS in different folder so that one i open script script gonna pick the files from the folders and i am gonna get the output in all folders different different

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

Please post screenshots clarifying the File/Folder-structure and the results you want to get.

Maybe this can help:

#target photoshop

// select a folder;

var sourceFolder = Folder.selectDialog("Select folder");

if (sourceFolder) {

// get the contents as one array per folder;

var theFiles = retrieveFiles(sourceFolder, [[]]);

alert (theFiles.join("\n"));

};

////// get from subfolders //////

function retrieveFiles (theFolder, theFiles) {

  if (!theFiles) {var theFiles = [[]]};

  var theContent = theFolder.getFiles();

  for (var n = 0; n < theContent.length; n++) {

  var theObject = theContent;

  if (theObject.constructor.name == "Folder") {

  theFiles.push(new Array)

  retrieveFiles(theObject, theFiles)

  };

  if (theObject.name.match(new RegExp(/\.(jpe|jpg|jpeg|gif|png|tif|tiff|bmp|psd|dng|pict|eps|raw|rw2|crw|cr2)/i)) != null) {

  theFiles[theFiles.length - 1].push(theObject)

  }

  };

  return theFiles

  };

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

Not Working LET ME EXPLAIN YOU WITH SCREEN SHOT

This is 1st Folder In which all other mockup files are there in diffrent diffrent folders

ALL MOCKS ARE IN THIS FOLDER .png

Now This is inside ALL FOLDER 2 Catagories With Mockup Files

THESE ARE THE 2 FOLDERS WITH MOCKUP FILE.png

NOW I WANT I WILL OPEN ALL FOLDER AND DONE THEN I CHOOSE IMAGES AND DONE APPLE I6 MOCKUP WILL CREATE READY FILES ON IPHONE 6 FOLDER AND GIONEE A1 MAKE FILES IN GIONEE A1 FOLDER

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

Not Working

The code was just an example of how to get the files in Folders within a selected Folder.

The screenshots do not seem to clarify the issue to me sufficiently.

Maybe you should start a new thread, that way you may attract somebody elseā€™s attention who may be able to help you better.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

LATEST

Ohk Actually You Write This Code So I Was Thinking You Know Better Then This Code Then Anyone Else

Let Me Give You One Example Like when we search in computers we get all the files even the files which Are in folder or in child folder

its like parent child then sub child game is like this

Convert All The Files Even In Subfolders THERE IS 1 FOLDER INSIDE THE FOLDER THERE IS ONE MORE FOLDER AND IN THAT FOLDER THERE ARE MOCKUPS LIKE THIS (ALL>IPHONE6>I6.PSD) STRUCTURE IS LIKE THIS  FOLDER>SUBFOLDER>MOCUP.PSD

WE HAVE TO CHOOSE FOLDER MOCUP.PSD WILL AUTOMATICALLY PIC

WHEN WE DO IMAGE PROCCESS IN PHOTOSHOP THERE WE GET OPTION LIKE INCLUDE SUB FOLDER LIKE THIS WE HAVE TO DO SAME

Screen Shot 2017-07-16 at 6.26.47 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

and how can i change Am Code ???

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2017 Jul 16, 2017

Copy link to clipboard

Copied

and how can i change Am Code ???

You can record AM code with ScriptingListener.plugin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines