Nested layerSet

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

tyr

Nested layerSet

Post by tyr »

Hi everyone,

I'm trying to make two scripts: one is 'lockAll = true' for current layer and another is 'lockAll = false' for all layers.

Everything worked fine until I tried to add a bunch of layer sets and nested layer sets. As far as I understand, I should check if layer's typename = layerSet and if so, work with it as an array of contained layers but I'm not getting how to check the nested layers for typename every time I encounter layerSet. And of course could be situations when the hole layerSet has been locked, not the individual layers.

Can you please help me to figure it out?

Thanks in advance,
Sergey.

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

pfaffenbichler

Nested layerSet

Post by pfaffenbichler »

Using Action Manager code would be quicker, but even in the DOM you can use a function that invokes itself.
The function collects the layers, but you could forego the adding to the Array (allLayers.push(…)) and just perform whatever task on the respective layers.
Code: Select allvar theLayers = collectLayers(app.activeDocument, []);
alert (theLayers.join("\n"));
////// function collect all layers //////
function collectLayers (theParent, allLayers) {
   if (!allLayers) {var allLayers = new Array}
   else {};
   for (var m = theParent.layers.length - 1; m >= 0;m--) {
      var theLayer = theParent.layers[m];
// apply the function to layersets;
      if (theLayer.typename == "ArtLayer") {
         allLayers.push(theLayer)
         }
      else {
         allLayers = (collectLayers(theLayer, allLayers))
// this line includes the layer groups;
         allLayers.push(theLayer);
         }
      };
   return allLayers
   };
tyr

Nested layerSet

Post by tyr »

Hello pfaffenbichler,

Thanks for your reply! Works like a charm.

Sergey.
pfaffenbichler

Nested layerSet

Post by pfaffenbichler »

Paul Riggott gave a Script in this thread that used Action Manager code to link all Layer Masks – it ran much faster than the DOM code, so if you ever feel the need for more speedy processing check it out, it should be possible to adapt it for your task.
http://forums.adobe.com/message/4628980#4628980