Skip to main content
Inspiring
May 15, 2023
Answered

Selection Index to pageItem Index?

  • May 15, 2023
  • 1 reply
  • 578 views

Hi,

Is it possible to convert a selection index to a pageItem index?

For instance, if my selection is sel[0] what corresponding pageItem[?] is that selection?

 

Javascript has a getIndex function but it doesn't work in ExtendScript it seems.

 

Thanks!

This topic has been closed for replies.
Correct answer femkeblanco

I think you have to iterate all the top level pageItems and check each pageItems[i] as to whether it references the same selected object. 

1 reply

femkeblanco
femkeblancoCorrect answer
Legend
May 15, 2023

I think you have to iterate all the top level pageItems and check each pageItems[i] as to whether it references the same selected object. 

iLLMonkeyAuthor
Inspiring
May 15, 2023

Hi,

Yes that did work thank you. I've created a simple function for this if anyone is interrested:

function findIndexInSelection(pageItems, selectionIndex){
  var doc = app.activeDocument;
  var sel = doc.selection;

  for (i=0;i<pageItems.length;i++){
    if (pageItems[i] == sel[selectionIndex])
    return i;
  }
}