Loop Through Doc layers based on bounds

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

norm

Loop Through Doc layers based on bounds

Post by norm »

Hey folks,

does anyone know if its possible to loop through a docs layers and return them based on layer bounds?

For example I want layer data returned in order based on the top margin layer bound, so layers that are closer to the top of the canvas are returned first working down to layers that are closer to the bottom of the canvas last.

Looking todo it in one loop?

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

Mike Hale

Loop Through Doc layers based on bounds

Post by Mike Hale »

Something like this?
Code: Select allvar doc = app.activeDocument;
var layers = [];
for(var index=0;index<doc.artLayers.length;index++){
    layers.push(doc.artLayers[index]);
}
layers.sort(customLayerSort);

function customLayerSort( a,b ){
    return a.bounds[1]-b.bounds[1];
}
norm

Loop Through Doc layers based on bounds

Post by norm »

ah of course .sort!

Thats perfect mike, thank you