Need script that export only visible layers to new folder

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

pfaffenbichler

Need script that export only visible layers to new folder

Post by pfaffenbichler »

but the script should not delete any layers or change visibility, only save visible layers to separate folder.
So?

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

DanielR

Need script that export only visible layers to new folder

Post by DanielR »

I've tried the script now.... thank you very very much. I works perfectly, except for one small but very significant thing. When it prompts me to save, and I browse to a folder and create a new folder and name it.. all is fine.

But then on the next round, when I need to go to the exact same parent folder, the script forgets the first round and the parent folder and starts at root. So I have to browse back down to the folder of choice. This is time consuming.

I can of course work only on the desktop, creating new folders there, this is ok, but then I need to move them from there etc. Is it hard work to make the script remember the folder position you think ? I'm not a coder so i don't know.

Thank you again..
pfaffenbichler

Need script that export only visible layers to new folder

Post by pfaffenbichler »

I assume you work on a Windows – and I don’t, so I don’t know about the folder selection dialog’s features there.

Anyway, I missed to check whether a folder has been selected, so you may want to replace the main body of the previous Script with
Code: Select allif (app.documents.length > 0) {
var myDocument = app.activeDocument;
// select folder;
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {
   var theLayers = collectVisibleLayers(myDocument, []);
// create a history state;
   myDocument.quickMaskMode = true;
   myDocument.quickMaskMode = false;
   var theState = myDocument.activeHistoryState;
// process the visible layers;
   for (var m = 0; m < theLayers.length; m++) {
      myDocument.artLayers.add();
      var theLayer = theLayers[m];
      hideOthers (theLayer, myDocument);
      deleteHiddenLayers ();
      savePNG (myDocument, theFolder, theLayer.name)
      myDocument.activeHistoryState = theState;
      };
   }
};
DanielR

Need script that export only visible layers to new folder

Post by DanielR »

It works like a charm... THANK YOU !!!!!