Indesign Script - Keep reference of nested pageItem in group while duplicating it
I am on InDesign 2023. VisualStudioCode.
I have a group of nested textFrames. In code, I track the textFrames by their id. Now I need to duplicate these groups, but still keep track of the textFrame duplicates.
Example: Let's say I have a group of pageItems (can contain deeply nested or anchored page items):
- Rectangle with id 1
- TextFrame with id 2
- TextFrame with id 3
- (and many more)
I need to insert text in TextFrame with id 2. No problem by getting it by id.
Now i need to duplicate the wrapping group to a new location. No Problem too. On duplicating, the id of the textFrame inside the group changes and I obviously lose my reference of it.
So what i do is to use the label of the textFrame to store the id as a string and recursively look for that in the duplicated group. This way i can identify the duplicated textFrame and continue using it, but is very slow for large groups and tons of duplicates.
So i was wondering if there's a more efficient way of accomplishing this task to keep a reference of a nested page Item in a group while duplicating it.
Any help appreciated.