Exporting Visible layers in photoshop 2020

Explorer ,
Nov 17, 2020

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.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()
TOPICS
Actions and scripting, Windows

Views

81

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Exporting Visible layers in photoshop 2020

Explorer ,
Nov 17, 2020

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.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()
TOPICS
Actions and scripting, Windows

Views

82

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 17, 2020 0
Explorer ,
Nov 17, 2020

Copy link to clipboard

Copied

oops, this line, sorry : (just above)

settings = current.visible;

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 17, 2020 0
Explorer ,
Nov 17, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 17, 2020 0
Explorer ,
Nov 18, 2020

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()

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 18, 2020 0
Adobe Community Professional ,
Nov 18, 2020

Copy link to clipboard

Copied

That's not exporting single layers, but simple saving visible ones.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 18, 2020 0
Explorer ,
Nov 18, 2020

Copy link to clipboard

Copied

That what i want ?!

see top of: 
I try to export only visible layer with this script found here

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 18, 2020 0
Adobe Community Professional ,
Nov 18, 2020

Copy link to clipboard

Copied

I mean exporting is not the same as saving, and in Photoshop these functions are similar only.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 18, 2020 0
Explorer ,
Nov 25, 2020

Copy link to clipboard

Copied

ha, exact !

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 25, 2020 1