This content has been marked as final.
Show 6 replies
-
1. Re: JS How to select the "first" text frame on a page
pkahrel Aug 24, 2008 11:34 AM (in response to Tom Tomasko)You need to compare the top of every text frame on that page and take the smallest value. Get the geometricBounds of each frame, which returns four-element arrays, then find the smallest value of the first element. E.g.
>myTextframe.geometricBounds[0]
returns the top of myTextframe. What you need to decide is whether 'first' is topmost AND leftmost. A frame could be the first one on a page vertically and second or third, horizontally.
Peter -
2. Re: JS How to select the "first" text frame on a page
(Dave_Saunders) Aug 24, 2008 11:57 AM (in response to Tom Tomasko)It doesn't have to be that clever, but yes, a script must determine that. This function will do the job. Just pass the page reference to it. Note that it considers only those text frames that are loose on the page.function getFirst(page) {Dave
// returns top-left text frame on page
var myFrames = page.textFrames.everyItem().getElements();
myFrames.sort(topLeft);
return myFrames[0];
function topLeft (a,b) {
aBounds = a.geometricBounds;
bBounds = b.geometricBounds;
if (aBounds[0] > bBounds[0]) return 1;
if (bBounds[0] > aBounds[0]) return -1;
if (aBounds[1] > bBounds[1]) return 1;
if (bBounds[1] > aBounds[1]) return -1;
return 0;
}
} -
3. Re: JS How to select the "first" text frame on a page
(Dave_Saunders) Aug 24, 2008 11:59 AM (in response to Tom Tomasko)On thinking about it, the function would be better named getTopLeft. Then the comment is probably not needed.
Dave -
4. Re: JS How to select the "first" text frame on a page
Tom Tomasko Aug 25, 2008 11:21 AM (in response to Tom Tomasko)Thanks, this will work. I wonder why Adobe set it up so that the most recently created text frame is the first in an array. -
5. Re: JS How to select the "first" text frame on a page
(Dave_Saunders) Aug 25, 2008 11:22 AM (in response to Tom Tomasko)So that when you create a new one you know where it is in the hierarchy.
Dave -
6. Re: JS How to select the "first" text frame on a page
L. Guy O'Rojo Aug 25, 2008 3:23 PM (in response to Tom Tomasko)Hi:
However, designers may manually slap slightly different-sized frames onto the page imprecisely. Therefore there may be no box which has both the highest top edge and leftmost left edge. I usually calculate the bounds of the live (permissible) area, divide it into a row-column grid, and then calculate which grid areas the centers of the frames are located within. This allows for more imprecise practices.
egr


