Copy link to clipboard
Copied
Hi,
I try to export only visible layer with this script found here :
https://community.adobe.com/t5/photoshop/exporting-visible-layers-in-photoshop-using-script/m-p/8276...
But somthing goes wrong with this line :
var current; // current layer reference
have you got an idea ?
thank
Ok, i fix it :
This script export only visible layer
function exportPNG(){
var documents = app.activeDocument;
var docName = app.activeDocument.name;
var docNameNoExt = app.activeDocument.name.split('.')[0];
var docPath = app.activeDocument.path.fsName;
var pngSrvOutput = new Folder("\\\\server_network\\production\\")
if (!pngSrvOutput.exists){
pngSrvOutput.create()
}
var isVisible = new Array();
//Show each layer each time and save a snapshot
for (var i = 0; i < documents.
...
Copy link to clipboard
Copied
oops, this line, sorry : (just above)
settings = current.visible;
Copy link to clipboard
Copied
ok, try to do it with anoterh way, but it exxport only first layer
var isVisible = new Array();
//Show each layer each time and save a snapshot
for (var i = 0; i < documents.layers.length; i++) {
isVisible = documents.layers[i].visible;
//Hide all the layers
for (var j = 0; j < documents.layers.length; j++) {
documents.layers[j].visible = false;
}
// show layer
var layerIndex = i;
documents.layers[layerIndex].visible = true;
var layerName = documents.layers[layerIndex].name;
// save
if (isVisible){
var file = new File(pngSrvOutput + "\\" + docNameNoExt + "_" + layerName + ".png");
var saveOptions = new PNGSaveOptions();
documents.saveAs(file, saveOptions, true, Extension.LOWERCASE);
}
}
I would like to export only visible layer
Copy link to clipboard
Copied
Ok, i fix it :
This script export only visible layer
function exportPNG(){
var documents = app.activeDocument;
var docName = app.activeDocument.name;
var docNameNoExt = app.activeDocument.name.split('.')[0];
var docPath = app.activeDocument.path.fsName;
var pngSrvOutput = new Folder("\\\\server_network\\production\\")
if (!pngSrvOutput.exists){
pngSrvOutput.create()
}
var isVisible = new Array();
//Show each layer each time and save a snapshot
for (var i = 0; i < documents.layers.length; i++) {
isVisible[i] = documents.layers[i].visible == true;
}
for (var i = 0; i < documents.layers.length; i++){
//Hide all the layers
for (var j = 0; j < documents.layers.length; j++) {
documents.layers[j].visible = false;
}
// show layer
if (isVisible[i]){
var layerIndex = i;
documents.layers[layerIndex].visible = true;
var layerName = documents.layers[layerIndex].name; // save
var file = new File(pngSrvOutput + "\\" + docNameNoExt + "_" + layerName + "-1.png");
var saveOptions = new PNGSaveOptions();
documents.saveAs(file, saveOptions, true, Extension.LOWERCASE);
}
}
for (var i = 0; i < documents.layers.length; i++){
documents.layers[i].visible = isVisible[i]
}
}
exportPNG()
Copy link to clipboard
Copied
That's not exporting single layers, but simple saving visible ones.
Copy link to clipboard
Copied
That what i want ?!
see top of:
> I try to export only visible layer with this script found here
Copy link to clipboard
Copied
I mean exporting is not the same as saving, and in Photoshop these functions are similar only.
Copy link to clipboard
Copied
ha, exact !