Skip to main content
Participant
February 16, 2022
Answered

Looking for a way to update smart objects from PSB via script

  • February 16, 2022
  • 1 reply
  • 779 views

I've written several scripts to automate a lot of this image pipeline I'm working on.

The last problem to solve is this:
Setup:
Primary PSD -> Contains several layers that are smart object to a secondary PSB

Secondary PSB -> Has several groups, inside each group are other smart objects/layers

My current manual steps:
1. Secondary PSB -> Make 'next' group visible

2. Secodary PSB -> Save PSB (ctrl+s)

3. Photoshop updates smart objects

4. switch back to Primary PSD document

5. Export As PNG

6. Choose name {SecondaryPSB_GroupName.png}

repeat 1-6 several times

 

I have scripts that I can modify to accomodate most of 1, 5 and 6. I'm having trouble finding examples where the script saves the PSB as the same filename, and then I'm not sure of a solid approach to waiting for step 3 to complete, can sometimes take 40+ seconds

 

I tried something like this, but it is either silently failing (I'm pretty sure) and/or it just isn't updating the smart object.

 

 

function SaveCurrentDoc(destinationFolder, shouldClose){
    var psdOptions = new PhotoshopSaveOptions();
    psdOptions.embedColorProfile = true;
    psdOptions.alphaChannels = true;
    psdOptions.layers = true;
    psdOptions.spotColors = true;

    var doc = activeDocument;

    doc.saveAs(new File(destinationFolder + '/' + doc.name.split('.')[0] + '.psb'), psdOptions);
    if(shouldClose){
        doc.close(SaveOptions.DONOTSAVECHANGES);
    }
}

 

This topic has been closed for replies.
Correct answer Kukurykus
with(activeDocument) save(), close()

1 reply

Kukurykus
KukurykusCorrect answer
Legend
February 16, 2022
with(activeDocument) save(), close()
Stephen Marsh
Community Expert
Community Expert
February 17, 2022

@Kukurykus 

 

As a beginner, I'm curious, your code appears the equivalent of the "more standard":

 

 

app.activeDocument.close(SaveOptions.SAVECHANGES);

 

 

What benefit (if any) does using  with()  add to the process, or is this just your personal coding style?

 

Kukurykus
Legend
February 17, 2022

Simply you don't have to repeat once used element. I'd ask why to use uneeded app. 'prefix'?