Skip to main content
lukej94472509
Participant
August 8, 2019
Question

Quick Export then Close Doc Script help

  • August 8, 2019
  • 2 replies
  • 853 views

Hey guys, fist time posting  - i got a script that opens a doc full of artboard it then updates the smart object on the artboards then exports all the artboard to a folder

i then need it to close the doc but everything i try makes the doc close before the export has taken place, i need it to export then close itself, script below, im new at scripting btw - thanks Luke

// Open Document 

newFile = new File ("Z:/Luke/Batch Processing/Batch Phones/01 - Cases.psb");

open (newFile);

// Update Document 

var idplacedLayerUpdateAllModified = stringIDToTypeID( "placedLayerUpdateAllModified" );

executeAction( idplacedLayerUpdateAllModified, undefined, DialogModes.NO );

// export activeDocument 

quick_export_png(activeDocument.path.fsName) 

  

// export activeLayer 

quick_export_png(activeDocument.path.fsName, true); 

    

    function quick_export_png(path, layer) 

        { 

        try 

            { 

            if (layer == undefined) layer = false;     

     

            var d = new ActionDescriptor(); 

            var r = new ActionReference(); 

     

            r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 

            d.putReference(stringIDToTypeID("null"), r); 

     

            d.putString(stringIDToTypeID("fileType"), "jpg"); 

            d.putInteger(stringIDToTypeID("quality"), 32); 

            d.putInteger(stringIDToTypeID("metadata"), 0); 

            d.putString(stringIDToTypeID("destFolder"), "Z:/Luke/Batch Final"); 

            d.putBoolean(stringIDToTypeID("sRGB"), true); 

            d.putBoolean(stringIDToTypeID("openWindow"), false);

           

            executeAction(stringIDToTypeID(layer?"exportSelectionAsFileTypePressed":"exportDocumentAsFileTypePressed"), d, DialogModes.NO); 

            } 

        catch (e) { throw(e); }

        }    

This topic has been closed for replies.

2 replies

Participant
October 22, 2022

Your script do the same job as it would if you hit tab File>Export>Quick Export As (PNG/JPG).
Result: layers are exported as PNG into folder.

Problem is when I add close document at the end of script activeDocument.close(...).
Result: layers are NOT exported, document is closed.
Any idea how to make this code export and then close?
Thank you!

JJMack
Community Expert
Community Expert
August 9, 2019

I do not see a close in the script are you sure the psb document opens. I also do see anything that updated smart object layers.  Are you expecting that the PSB files contain Place linked smart oobject layers the the linked files have been updated by some other process? Are you sure that the document is being closed before the export. Are you sure  that the script is not failing before the export? That the update document part is working that it is not failing.

JJMack
lukej94472509
Participant
August 9, 2019

Maybe Im not explaining right..

newFile = new File ("Z:/Luke/Batch Processing/Batch Phones/01 - Cases.psb");

open (newFile);

opens my .psb - that contains lot of artboard

The Phones are the smart objects that after the .psb opens automatically update

var idplacedLayerUpdateAllModified = stringIDToTypeID( "placedLayerUpdateAllModified" );

executeAction( idplacedLayerUpdateAllModified, undefined, DialogModes.NO );

then after the update, photoshop saves all the artboard as .jpgs to a folder i've picked

quick_export_png(activeDocument.path.fsName, true); 

    

    function quick_export_png(path, layer) 

        { 

        try 

            { 

            if (layer == undefined) layer = false;     

     

            var d = new ActionDescriptor(); 

            var r = new ActionReference(); 

     

            r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 

            d.putReference(stringIDToTypeID("null"), r); 

     

            d.putString(stringIDToTypeID("fileType"), "jpg"); 

            d.putInteger(stringIDToTypeID("quality"), 32); 

            d.putInteger(stringIDToTypeID("metadata"), 0); 

            d.putString(stringIDToTypeID("destFolder"), "Z:/Luke/Batch Final"); 

            d.putBoolean(stringIDToTypeID("sRGB"), true); 

            d.putBoolean(stringIDToTypeID("openWindow"), false);

           

            executeAction(stringIDToTypeID(layer?"exportSelectionAsFileTypePressed":"exportDocumentAsFileTypePressed"), d, DialogModes.NO); 

            } 

        catch (e) { throw(e); } 

        } 

the same as it would if you hit File>Export>Quick Export As..

when i add a line after this telling photoshop to close the document, it opens, updates smart objects, then closes before the export happens, its like it jump past the export stage or closes before the export happens

Many thanks

Luke

JJMack
Community Expert
Community Expert
August 9, 2019

Are you sure that automatic update code is working or if even needed.  I would think any Smart Object layers that have linked  object that have changed would automatically be updated when the psb is opened if the link has not been broken.    What process was used to Change the  linked objects. If you are trying to updated products you should not want everything in one huge PSB file.  Its like you creating a single point of failure with poor performance  overtaxing Photoshop using a huge file with huge overhead of updating so many smart object layer.  I do not believe you know what you are doing.

Your PSB reminds me  of a thread in Adobe Photoshop Forum Re: Running a script within an action Where Batch populating 84 Products mockups with 41 different lable that is 3,444 output Jpg files took my machine over an hour and a half to save.

JJMack