| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hello, The following will select a text frame on the first page of a document. However textFrames.item(0) refers to the most recently created text frame, which is not very useful. Is there a property in the object model that allows for selecting the first text frame--based upon its position (highest and most left)--or must a clever script be written? app.activeDocument.pages.item(0).textFrames.item(0 ).select(); Thanks, Tom |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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) { // 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; } } Dave |
|
#4
| |||
| |||
| On thinking about it, the function would be better named getTopLeft. Then the comment is probably not needed. Dave |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.