Search code examples
javascriptphotoshopphotoshop-script

photoshop script - Is it possible to get O(1) access to layers?


I have a photoshop file with 10k layers, iterating through them takes too much time since its a O(n) process. Is there any way to find layers using a O(1) method? What I'm looking for concretely is a fast way to select all layers with specific same name (for example all layers named "layerA"), without iteration.


Solution

  • As long as the layer names are unique, use:

    var srcDoc = app.activeDocument;
    var myLayerName = "Layer 1";
    srcDoc.activeLayer = srcDoc.artLayers.getByName(myLayerName);
    

    In the event that there are two or more layers named "Layer 1", the code above will pick the top most layered called "Layer 1".