Search code examples
photoshop-scriptphotoshop-cs5

How to identify clipping masks in Photoshop using JavaScript


I've currently butchered a script I was reading that loops through a list of layers, and then looks for layers with a certain name (3/2, 4/3 etc). The next step is to check for layer masks that are clipped to the base layer, and merge them to it. I've read through the reference docs, and can't find anything about identifying clipping masks. I've attached an image as an example of how the document is structured.

enter image description here

And here is the code I have so far:

var doc = app.activeDocument  
var ratios = ["1/1", "4/3", "3/4", "3/2", "2/3", "16/9", "9/3", "7/2", "11/5"];  

for (var i = 0, il = doc.layers.length; i < il; i++) {  
    var curLayer = doc.layers[i];  
    for (var j = 0, jl = ratios.length; j < jl; j++) {  
        if (curLayer.name == ratios[j]) {  
            alert(curLayer.name); 
            // Check for clipping masks attached to this layer
        }
    }  
}  

I am using Photoshop CS5. Thanks!


Solution

  • I ended up working out another way to do it. I instead grouped the layers into a layerset, and exported them out of the document that way. For those that would like to see it, have a look here:

    https://gist.github.com/BeauAgst/4da366b933cc75a0606a