Cycle through layers, comparing current layer object against every other layer object
I want to loop through each layer in my document (which has only 1 object on each layer) to compare the selected item's width and height against all other layers' object's width and height. I have started with comparing the first layer[0] against the rest of the layers following - see script below. But how do I then loop it again, but start at the second layer [1], loop through to the end of the layers and also come back to include layer[0] in that loop. Then loop through again, starting at the third layer [2], loop through to the end of the layers and then include layer[0] and [layer1] in that loop, and so on till I've checked all layers.
var docRef=app.activeDocument;
// Select the first layer and the layer contents
docRef.activeLayer = app.activeDocument.layers[0]; // unhide the first layer
docRef.activeLayer.hasSelectedArtwork = true; // selects artwork in active layer
// Show all layers in the document
showAllLayers();
var objWidth = app.selection[0].width;
var objHeight = app.selection[0].height;
var total = 0;
var items = docRef.pageItems;
var n = items.length;
for (i=0; i<n; i++) {
var item = items[i];
// Compare width and height
if (item.width == objWidth
&& item.height == objHeight )
{
item.selected = true;
// For keeping track of which layers have same sized object
if (item.selected == true) {
total += ([i] + ", ");
}
}
}
alert("Layers with same sized object: " + total.toString());
// FUNCTIONS
function forEach(collection, fn)
{
var n = collection.length;
for(var i=0; i<n; ++i)
{
fn(collection[i]);
}
}
function showAllLayers()
{
forEach(docRef.layers, function(layer) {
layer.visible = true;
});
}
