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

Batch Script To Replace 2 Smart Objects And Save The Final Image

Community Beginner ,
Apr 15, 2023 Apr 15, 2023

Copy link to clipboard

Copied

Hi everyone,

 

My knowledge of coding is unfortunately very minimal, and I've been having a really hard time for the better part of the day trying to figure out how to do this following other answers I've seen on here.

 

I have a mock up PSD that has 2 smart objects within it and I have 2 folders each with an equal number of images in them.

 

I need a script that can replace the first smart object with an image from the first folder and the second smart object with an image from the second folder and then export the whole thing. There's about 700~ images in both of the folders so I need it to run through all of them if possible.

As an example it would export like this.

 

Fortunately the images have mirrored names across the folders (i.e image1-side-a and image1-side-b) so I don't need the script to look for filenames or anything like that.

 

Any help would be extremely appreciated.

TOPICS
Actions and scripting

Views

4.5K

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 2 Correct answers

Community Expert , Apr 17, 2023 Apr 17, 2023

@NelNelD – I have updated the code to a 1.1 version, the lower smart object layer is now removed.

 

EDIT: Let me know how it goes. I have now updated to a 1.2 version so that all layers in the smart object are removed, except the top layer.

 

I have updated the code to version 1.3 to remove any photoshop:DocumentAncestors metadata build-up in the smart objects and or main PSD file which may bloat the file size after multiple uses.

Votes

Translate

Translate
Community Expert , Jun 21, 2024 Jun 21, 2024

@ci2own 

 

Here is the revised script for your specific template and assets:

 

/*
Video Game Smart Object Layer Replacements to PNG.jsx
Version 1.0 - 22nd June 2024, Stephen Marsh
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/batch-script-to-replace-2-smart-objects-and-save-the-final-image/m-p/13728400
*/

#target photoshop

    (function () {

        try {

            var selectFile = File.openDialog("Select the template file:");
            open(selectFile);

     
...

Votes

Translate

Translate
Adobe
Explorer ,
Jun 22, 2024 Jun 22, 2024

Copy link to clipboard

Copied

The ppi value of the files that place smaller was 300ppi (I resized them with IrfanView).

 

Captura de pantalla 2024-06-22 a las 19.08.21.png

 

Thanks to you, I realized the Box Front images must be 960x1357 and 72ppi, and the Box Spines images must be 231x1357 and 73ppi too, to work with your script.

 

Captura de pantalla 2024-06-22 a las 19.05.04.png

I can easily do that with IrfanView or by placing all images in the smart object layer, resize, and batch export them with photoshop.

 

Thanks again to make me save a lot of time. Let me know how can i invite you a beer 🙂

 

 

 

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 ,
Jun 22, 2024 Jun 22, 2024

Copy link to clipboard

Copied

LATEST
quote

Thanks to you, I realized the Box Front images must be 960x1357 and 72ppi, and the Box Spines images must be 231x1357 and 73ppi too, to work with your script.

 


By @ci2own

 

It's not just my script, if you were doing this manually you'd have the same issue, it's how smart object replacement works.

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 ,
Jun 22, 2024 Jun 22, 2024

Copy link to clipboard

Copied

quote

And also i realized doing some tests, the example images fits perfect on the result box, because i exported them from the same template, but when image size don't match the one in the smart object, it doesn't addapt it automatically:


By @ci2own

 

This is how smart objects work. You need to ensure that all assets are as follows:

 

Spine replacement image = 231 x 1357px @ 72ppi

 

Box Front replacement image = 960 x 1357 @ 72ppi

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