Highlighted

script to batch smart object

New Here ,
Sep 23, 2020

Copy link to clipboard

Copied

I have a mock-up template with sveral layers and a smart object where to put the image into this works perfect for one picture but i whant to do it on multiple pictures.

anyone who can help me with this? i have minimul script knowledge but found this 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.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", 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, theLayer);

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

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

};

TOPICS
Actions and scripting

Views

119

Likes

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

script to batch smart object

New Here ,
Sep 23, 2020

Copy link to clipboard

Copied

I have a mock-up template with sveral layers and a smart object where to put the image into this works perfect for one picture but i whant to do it on multiple pictures.

anyone who can help me with this? i have minimul script knowledge but found this 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.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", 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, theLayer);

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

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

};

TOPICS
Actions and scripting

Views

120

Likes

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
Sep 23, 2020 0
Most Valuable Participant ,
Sep 23, 2020

Copy link to clipboard

Copied

If your template have the smart objects layers that need their content populated on top of the layer stack  and the objects in the template are photoshop object like a psd. You should be able to use my BatchMockupTemplates.jsx its a script in my free download Photoshop Photo Collage and mockup Toolkit 

Either Replace Content or Edit Content can be used to update the Smart Object layers.

JJMack

Likes

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
Reply
Loading...
Sep 23, 2020 0
New Here ,
Sep 25, 2020

Copy link to clipboard

Copied

Hi jjmack,

 

Thanks 4 your quick notice, i just downloaded your scripts and tried it on a mockup psd but got below errors.

--required folder missing c:\test\obj1

 

is it an idea i email you the files i have so you can test it or?

 

Likes

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
Reply
Loading...
Sep 25, 2020 0
Most Valuable Participant ,
Sep 25, 2020

Copy link to clipboard

Copied

You did not read the help. when a mockup the has more than a single Smart Object layer to be replaces you have your image collection is a folder in sub folders for each smart object layer the be replaced.  The Sub folder must be named obj0, obj1 , ... objN.   The top smart object layer will be populated with replacement in "obj0" folder.  The next lower layer with the image in "obj1" and so on.  The Script is simple It know nothing about  your images.  The images  are process in file name order.  Your need name your files so they will be populated together the first image in the folder are populated together.  You can use any naming convention that works for you.  Each sub folder is a queue for a layer in the layer stack.  the queues are processed in file order.

 

The script BatchReplaceOneObject.jsx was my prototype script is the only script the does not require  the sub folders for it can only replace the top smart object layer and only process one template

JJMack

Likes

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
Reply
Loading...
Sep 25, 2020 0
New Here ,
Sep 28, 2020

Copy link to clipboard

Copied

jjmack YES this works BatchReplaceOneObject.jsx  🙂

what a beatifull script we are very glad. we will donate if you whant!

 

Likes

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
Reply
Loading...
Sep 28, 2020 0
New Here ,
Sep 28, 2020

Copy link to clipboard

Copied

also i have one other psd file which contains 3 masks and i only need to copy past a picture in the second mask but i whant to batch it is this also possible? becuase when i try to batch it photoshop cant batch copy and paste

Likes

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
Reply
Loading...
Sep 28, 2020 0
JJMack LATEST
Most Valuable Participant ,
Sep 28, 2020

Copy link to clipboard

Copied

BatchMockupTemplates.jsx can populated one or more mockup templates with the same replacement objects. A mockup template can contain one or more smart object layer on the top of the layer stack to be populated with a  replacement.  

 

BatchMockupTemplates.jsx can do what BatchUpdateSmartObject.jsx and BatchReplaceOneObject.jsx scripts can do.  They are redundant. I coded BatchReplaceOneObject.jsx first to see if I could replace object  via Replace content or Edit Content.  After R-bin posted code that allowed me to determine if a smart was a Photoshop object that I could edit in Photoshop.  My script would loose control if  I opened a smart object the was a Camera RAW or Vector Smart Object.   That was the problem I was never able to overcome in the past. I only hack at Photoshop scripting.  I do not know Javascript or all that there is to know about Adobe DOM and Action Manager Code. BatchReplaceOneObject.jsx can only replace the top Smart Object layer's object.

 

I then coded BatchUpdateSmartObject.jsx  to bet able to replace all top smart object layers objected. I needed to have a source of replacement a queue for each smart object layer  So I added the requirement of sub folders replacements  objects obj0, obj1, .... obkN.

 

Then I coded BatchMockupTemplates.jsx  for a user wanted to be able to populate a collection of Candy jar mockup with the same label objects.  So I added a queue for Mockup templates.

 

Since I could not populate a queue of templates. It came to me that if I did not batch populate the templates,  just do a single population of each with the next set of replacement objects.  That I could populate a coffee table book populate page mockups thus I coded PopulateAlbumPageMockups.jsx

 

 

Your mockup Layer stack is what determine what get replacements

JJMack

Likes

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
Reply
Loading...
Sep 28, 2020 0
LEGEND ,
Sep 25, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Sep 25, 2020 0