Skip to main content
orib7317974
Known Participant
July 18, 2023
Question

Efficiently getting item by id without container

  • July 18, 2023
  • 2 replies
  • 482 views

Is there a way for an InDesign script to efficiently get a document item, given its id, if it doesn't already have its container (parent)?

I'm hoping for something like a global mapping of ids to items for all items in the document.

Thanks! 

This topic has been closed for replies.

2 replies

Community Expert
July 19, 2023

Hi @orib7317974,

@rob day has discussed almost all the ways we can use to refer a pageItem. If none of this is what you desire then can you share some screenshots, InDesign document and describe a usecase that you are trying to handle so that we can think more about it.

-Manan

-Manan
orib7317974
Known Participant
July 19, 2023

@rob day & @Manan Joshi , thank you very much for your help!

I think I now understand pretty well what my options are.

I have some thinking to do. There are efficiency concers, maybe I'll conduct some experiments.

For now I consider my question fully answered 🙂

rob day
Community Expert
Community Expert
July 18, 2023

Hi @orib7317974 , Could you give an example of a page item that doesn’t have a parent? Do you mean a page item whose parent is a placeGun?

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PageItem.html

orib7317974
Known Participant
July 18, 2023

Hi @rob day , it's not about that, sorry for my confusing wording, by 'it' I was referring to the script, not the item.

I'm interested in an efficient and simple way of getting the item when I don't already have its parent.

True, I could always do a tree search, or build a global mapping myself, but I was hoping I wouldn't have to.

rob day
Community Expert
Community Expert
July 18, 2023

If the page item is placed on the page via a script, you could capture its ID or give it a label when it’s created, which could be used to find the item later in the script.

 

If it’s in an existing document there’s no way of knowing its ID. If the document was setup via a template, the page items could be given script labels for identification in the Script Label panel.

 

If it‘s none of the above, maybe provide an example.