Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var selection = app.selection[0];
var zIndex = getStackingIndex( selection, true );
$.writeln( zIndex );
// Since the last parameter is set to false, this selectPageItem() mirrors the selection
// - If first item is selected when the script is run, the last one will be
// selected when the script is done.
selectPageItem( selection.parentPage, zIndex, false );
// cssMode reverses the order → Frontmost item is the highest number.
function getStackingIndex( pageItem, cssMode ) {
var page = pageItem.parentPage;
var pageItems = page.allPageItems;
if ( cssMode ) pageItems = pageItems.reverse();
var length = pageItems.length;
for ( var i=0; i < length; i++) {
var loopItem = pageItems[i];
if ( pageItem === loopItem ) {
pageItem = i;
break;
}
}
return pageItem;
}
// cssMode reverses the order → Frontmost item is the highest number.
function selectPageItem( page, index, cssMode ) {
if ( cssMode ) {
var reversedItems = page.allPageItems.reverse();
app.selection = reversedItems[ index ];
}
else {
app.selection = page.allPageItems[ index ];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment