Skip to main content
Participant
March 21, 2009
Question

Scripts / Export Layers to Files / Include Background Layer

  • March 21, 2009
  • 1 reply
  • 994 views
Running the script Export Layers to files.
Need to keep one layer on that is applied to all the layers (I have a stroke on the top layer I would like applied to all the images that are saved out.)

How do I modify the script for this?
Thanks!
Ken
This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
March 22, 2009
Adapting that Script might be somewhat difficult as it is pretty bulky.
But if its always the topmost layer thats supposed to stay visible and You know which format You want to save the resulting files to beforehand something much smaller may suffice.
You might try this, but I havent tested it extensively:


#target photoshop;

var myDocument = app.activeDocument;

// get the name and location;

var docName = myDocument.name;

var basename = docName.match(/(.*)\.[^\.]+$/)[1];

var docPath = myDocument.path;

// get the artlayers and remove the topmost;

var allArtLayers = collectLayers(myDocument);

var theTopmost = allArtLayers.pop();

// hide all but the topmost layer;

for (var n = 0; n < allArtLayers.length; n++ ) {

allArtLayers.visible = false

};

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

// show the layer;

allArtLayers.visible = true;

// tiff options;

tifOpts = new TiffSaveOptions();

tifOpts.embedColorProfile = true;

tifOpts.imageCompression = TIFFEncoding.TIFFLZW;

tifOpts.alphaChannels = false;

tifOpts.byteOrder = ByteOrder.MACOS ;

tifOpts.layers = true;

// duplicate the image;

var thecopy = myDocument.duplicate (thecopy, true);

// save copy;

thecopy.saveAs((new File(docPath+"/"+basename+" "+allArtLayers.name+".tif")),tifOpts,true);

thecopy.close(SaveOptions.DONOTSAVECHANGES);

// hide the layer again;

allArtLayers.visible = false

//thats it; thanks to xbytor;

};

////// collect all artlayers //////

function collectLayers (theParent) {

if (!allArtLayers) {

var allArtLayers = new Array}

else {};

for (var m = theParent.layers.length - 1; m >= 0;m--) {

var theLayer = theParent.layers;

// apply the funtion to layersets;

if (theLayer.constructor == ArtLayer) {

allArtLayers = allArtLayers.concat(theLayer)

}

else {

allArtLayers = allArtLayers.concat(collectLayers(theLayer))

}

};

return allArtLayers

};