• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Replacing Multiple Smart Objects via Script

New Here ,
Apr 18, 2022 Apr 18, 2022

Copy link to clipboard

Copied

I am using the following script, but would like to edit multiple smart objectives within my mockup template file. Basically my template file has a desk coaster and a mouse pad. The issue is that my image files will be different sizes. Is there a way to modify the script or another automated process to develop the mouse pad & coaster with the same image?

 

// Replace SmartObject’s Content and Save as JPG

// 2017, use it at your own risk

// Via @circle B: https://graphicdesign.stackexchange.com/questions/92796/replacing-a-smart-object-in-bulk-with-photos...

// JPG code from here: https://forums.adobe.com/thread/737789

#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;

    // JPG Options;

    jpgSaveOptions = new JPEGSaveOptions(); 

    jpgSaveOptions.embedColorProfile = true; 

    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 

    jpgSaveOptions.matte = MatteType.NONE; 

    jpgSaveOptions.quality = 11;  

    // Check if layer is SmartObject;

    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", "*.png;*.psd;*.tif;*.jpg", true)

        } else {

            var theFiles = File.openDialog("please select files", getFiles, true)

        };

        if (theFiles) {

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

                // Replace SmartObject

                theLayer = replaceContents(theFiles[m], theLayer);

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

                // Save JPG

                myDocument.saveAs((new File(thePath + "/"  + theNewName + ".jpg")), jpgSaveOptions, true,Extension.LOWERCASE);

            }

        }

    }

};

// Get PSDs, TIFs and JPGs from files

function getFiles(theFile) {

    if (theFile.name.match(/\.(png|psd|tif|jpg)$/i) != null || theFile.constructor.name == "Folder") {

        return true

    };

};

// Replace SmartObject 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

};

//Alert Letting the User Know the Script Has Finished

alert("Finished!\nThe script has finished saving the jpeg thumbnails in the folder with the original mockup");

TOPICS
Actions and scripting , Windows

Views

1.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
Adobe
Community Expert ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Perhaps one of these scripts can help:

 

http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html

 

If you search the forum you will also find many other SO replacement scripts.

 

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 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Hey @Stephen_A_Marsh I searched the forums on replacing multiple SO scripts within one mockup. I have previously browsed and attempted to use the PHoto Collage Tool Kit pack, but was not successful. If you could point me to some threads on replacing multiple SO scripts I would be be very thankful! 

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, 2022 Apr 20, 2022

Copy link to clipboard

Copied


@lido240674372bja wrote:

I have previously browsed and attempted to use the PHoto Collage Tool Kit pack, but was not successful. 


 

Why weren't you successful? Did you follow the 4 rules?

 

There are three scripts that may possibly be suitable:

 

BatchUpdateSmartObject.jsx - Used to populate simple Mockup templates like BatchReplaceOneObject script but can update more than a single smart object layer.


BatchMockupTemplates.jsx - Used to populate multiple Mockup Templates that needs to be populated with the same replacement image objects.


PopulateAlbumPageMockups.jsx - Used to populate a collection of Photo Page Mockup templates for a Picture Album.

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 24, 2022 Apr 24, 2022

Copy link to clipboard

Copied

I attempted to use BatchUpdateSmartObject

The issue was it was only replacing one smart object. 

Simple Mockup Template File Structure:

lido240674372bja_0-1650808000608.png

Objects Collection Folder Had 2 Subfolders named obj0 & obj1

lido240674372bja_1-1650808102510.png

 

Output is desktop and selection is edit smart objects. 

The script is only editing the top level SO and saving. I'm not sure what I'm doing wrong. Both obj subfolders have the exact same number of images.

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
LEGEND ,
Apr 24, 2022 Apr 24, 2022

Copy link to clipboard

Copied

Export top SO's, then link both SO's to exported content and change them to embedded.

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 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Are you saying to run the original script and save each one as PDF and manually go through each mock up to save singular design?

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
LEGEND ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

No. You export content of Smart Objects by Layers panel contextual menu.

After you link them all singly to the same file, they'll contain same content. 

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 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

@Kukurykus i'm not tracking what you are recommending.

 

@Stephen_A_Marsh did my screen shots helps? 

 

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
LEGEND ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

LATEST

Didn't you look solution for: "The issue was it was only replacing one smart object."?

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 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Please provide meaningful screenshots to illustrate the Layer and file-structure. 

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 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Thanks for your assistance. See below

lido240674372bja_0-1650423255632.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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

lido240674372bja_0-1650423586819.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
Community Expert ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

That screenshot seems to illustrate neither.  

 

Please provide a meaningful description, including screenshots, of the intended process. 

Will there be two files for the two different crops of the switch-in-image, will the two Smart Objects contain Smart Objects of the same image to create the two crops, …? 

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, 2022 Apr 20, 2022

Copy link to clipboard

Copied

I would like to drop in two images of the same image to replace the SO of the coaster and desk set. The current script calls only the selected SO to be replaced and saved. 

lido240674372bja_0-1650507883854.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
Community Expert ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Your explanations and screenshot-snippets seem insufficient to me. 

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
Community Expert ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

As far as getting the replaced smart object images to be the same size, as the original image, you can try the script on this link:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/paste-image-to-fit-smart-layer/m-p/12...

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