I'm working with an InDesign document that contains two layers--layer one contains empty frames and layer two contains content in text frames. The empty frames dictate the positioning of the content in text frames, so ideally, a search for text in layer two would be organized based on the structure in layer one.
This was my thought process in approaching this task.
1. Retrieve empty text frames in layer one
2. For each retrieved text frame, obtain X,Y coordinates
3. Search within those X,Y coordinates for text of a particular style in layer two
4. Repeat for all other text frames in layer one
The hangup that I'm having right now is with step three.
Is it even possible to find text based on coordinates, rather than a text frame? InDesign documentation states that the find method is only applicable to text frames but I'm hoping that this method can also be used with visual bounds. Any other suggestions or comments would be greatly appreciated.
The documentation is correct. You cannot use some handy function to find the text on some coordinates. Perhaps Adobe didn't think of this because in the UI, well, you just look at those coordinates.
However, not all is lost -- you only have to do the coordinate-matching stuff yourself. The position of single characters can be approximated by using horizontalOffset (giving you the x-position of the left side of the character or insertion point) and the baselineOffset (giving you the y-position). There is, unfortunately, nothing to reliably check the top of a certain text, so you'll have to make do with something like 'baselineOffset + point size'.