Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joonaspaakko/ad59e1f33ba953f622f6765b65b5854c to your computer and use it in GitHub Desktop.
Save joonaspaakko/ad59e1f33ba953f622f6765b65b5854c to your computer and use it in GitHub Desktop.
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