From 5c2ad5a4201deda9320fa280ff489bd98018fb7e Mon Sep 17 00:00:00 2001 From: Yanko Oliveira Date: Sat, 13 May 2023 08:54:07 +0100 Subject: [PATCH] Exporting a single layer now supports folders. Fixes issues when using the "Active Layer Only" and "Inpaint Selection" when folders are present in the document. --- javascript/photopea-scripts.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/javascript/photopea-scripts.js b/javascript/photopea-scripts.js index 1202db3..adcead3 100644 --- a/javascript/photopea-scripts.js +++ b/javascript/photopea-scripts.js @@ -9,7 +9,21 @@ // below, then its done, and that solves the promise, but we end up with a dangling "done" // response from the script execution message. But hey, if it works... ^^' function exportSelectedLayerOnly() { - var allLayers = app.activeDocument.layers; + // Gets all layers recursively, including the ones inside folders. + function getAllArtLayers (document, layerCollection){ + for (var i = 0; i < document.layers.length; i++){ + var currentLayer = document.layers[i]; + if (currentLayer.typename === "ArtLayer"){ + layerCollection.push(currentLayer); + } else { + getAllArtLayers(currentLayer, layerCollection); + } + } + return layerCollection; + } + + var allLayers = [] + allLayers = getAllArtLayers(app.activeDocument, allLayers); // Make all layers except the currently selected one invisible, and store // their initial state. layerStates = []