indesign-extendScript to group items by page and layer
Hello all,
I've been working on this small script :
var docA = app.activeDocument,
lastPage = docA.pages.lastItem(),
group_it = function() {
var group0 = [];
for(var i = 0; i<=docA.layers.length-1; i++){
for(var j = 0; j<=lastPage.pageItems.length-1; j++){
if (lastPage.pageItems[j].itemLayer.id == docA.layers[i].id) {
alert(docA.layers[i].id + " - " + lastPage.pageItems[j].id);
group0[i] = lastPage.groups.add(lastPage.pageItems[j],docA.layers[i],LocationOptions.AT_END);
group0[i].name = "myGroup" + i;
}
}
}
};
group_it();I tested it with a document with 3 layers, 2 pages and 4 items... But it always seems to give me an error at the line where the grouping occurs (group0[i] = lastPage...).
If I comment that line and the one following it, the alert box shows me the correct number of items-id.
I have to say, I'm rather puzzled by the whole thing... If some kind soul could shed some light on this problem, I would be most gratefull.
Mike
