0

I have a nested grouping structure that looks something like:

TOP GROUP > NESTED GROUP > (Layers go here)

My goal is to hide and reveal these layers, and I'm able to do this to the top group by using:

app.activeDocument.layerSets.getByName("TOP GROUP").visible = true;

However, whenever I attempt to reach the nested group via the same script I get an error:

Error 1302: No such element

I understand this is because the script is unable to find the nested group due to it not being top-most, as the script will not do any digging to reach it.

That said, is there a simple way to reach a group nested within another group? I understand there are ways to do this using Action Manager, but I would prefer to keep this in JavaScript as I'm at least a little familiar with it while I have no experience at all with Action Manager.

1 Answers1

0

layerSets are arrays with arrays inside. You can browse it recursively something like:

function browseLayerSets(o){

    for(var i = o.layerSets.length-1; 0 <= i; i--) {
        var layerSet = o.layerSets[i];
        // layerSet.doSomething ...
        browseLayerSets(layerSet)
    }
}

If you know exactly what you want, you can use:

app.activeDocument.layerSets[0].layerSets[/*your item index*/].layerSets[/*your item index*/] ...
Jarda
  • 31
  • 1
  • 3