Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Selection Index to pageItem Index?

Participant ,
May 15, 2023 May 15, 2023

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!

TOPICS
Scripting
466
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , May 15, 2023 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. 

Translate
Adobe
Guide ,
May 15, 2023 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 15, 2023 May 15, 2023
LATEST

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;
  }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines