Skip to main content
Participant
August 2, 2021
Question

How do I batch export layers in a cumulative way? Better explanation in post.

  • August 2, 2021
  • 1 reply
  • 334 views

Okay, so I have a bit of a conundrum. I’m trying to streamline my workflow for a current project.

The project involves a background image with a number layers on top. I need to find an automated way of exporting the background image with each of these layers, in a cumulative fashion.

 

So:

 

First exported image = BG image +layer 1

 

Second exported image = BG image +layer 1 +layer 2

 

Third exported image = BG image +layer 1 +layer 2 +layer 3

 

... etc

 

I need to export 10,000 images in total (over multiple documents), so finding a solution to this that radically reduces the time invested would be most appreciated.

 

I've found an old script that will export each layer with the BG image sequentially in illustrator (a solution in either illustrator or photoshop will work), but not cumulatively. It can be found here: Export Illustrator Layers and/or Artboards as PNGs and PDFs - I just don't know how to edit the script to make the (presumed) minor tweak to achieve what I'm looking for.

 

If anyone has any alternative solutions, I'm all ears.

 

Thank you!

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
August 2, 2021

Are Groups involved or not? 

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible? 

What is the intended naming convention? 

Participant
August 2, 2021

No groups are involved.

In terms of naming convention, there isn't any, as long as they are in the correct order displayed in the document. So even just image_1, image_2, image_3 etc, would suffice, as long as it's sequentially correct. I plan to batch rename the files after the export.

Legend
August 2, 2021

What format did you plan to export the files to?

 

here is a simple script:

#target photoshop

s2t = stringIDToTypeID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('hasBackgroundLayer'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'))
var offset = executeActionGet(r).getBoolean(p) ? 0 : 1;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayers'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p);

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('fileReference'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var pth = executeActionGet(r).getPath(p).parent;

for (var i = lrs.count - 1; i >= 0; i--) {
    (r = new ActionReference()).putIndex(s2t('layer'), lrs.getReference(i).getIndex(s2t('itemIndex')) + offset);
    (d = new ActionDescriptor()).putReference(s2t(('null')), r);
    executeAction(s2t('show'), d, DialogModes.NO);

    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
    r.putIndex(s2t('layer'), lrs.getReference(i).getIndex(s2t('itemIndex')) + offset);
    var nm = executeActionGet(r).getString(p);

    var pngOpts = new ExportOptionsSaveForWeb;
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false;
    pngOpts.transparency = true;
    pngOpts.interlaced = false;
    pngOpts.quality = 100;
    activeDocument.exportDocument(new File(pth + '/' + nm + '.png'), ExportType.SAVEFORWEB, pngOpts);
}


* initial state of the document - the visibility of the layers that are planned to be exported is turned off. On the layers palette, only those layers are selected that need to be sequentially exported.
* files with the name of the layer are exported to the same directory from which the document was opened