-1

I am trying to get all the text frames for a single page in order but I was always getting them in random order when using the

myDoc.pages[1] //assuming the 1st index page
>> [object Page]
myDoc.pages[eachPage].textFrames   //get all the text frames on that page.
>> [object TextFrames]     //able to get the textframes but they are not in the order if they are linked textframes

Is there a way to get them in order if they are linked text frames? (not sure how they will come up if they are unlinked)

If not at least how to know the first text frame on the page so I can get the other frames with . nextTextFrame.

RobC
  • 22,977
  • 20
  • 73
  • 80
Sundeep Pidugu
  • 2,377
  • 2
  • 21
  • 43
  • In this scenario, can we assume that all linked text frames are on the same page? Or is it a chain of linked text frames that maybe starts on a prior page and continues onto a next page? – mdomino May 05 '20 at 23:22
  • All are linked text frames on the first page and they might have a chain from the previous page which is basically having a chain that extends from the last text frame to the next page. – Sundeep Pidugu May 05 '20 at 23:56

1 Answers1

2

Basically you will have to start with any text frame and from this find all linked text frames and then in a third step collect just those that are on your page. Here is how you could go about it:

// get your document and your page somehow
var doc = app.activeDocument;
var myPage = doc.pages[1];

// get any text frame on your page and from its parent story get the
// text containers which is an array of all text frames that contain
// the linked text story
var someTextFrame = myPage.textFrames[0];
var textContainers = someTextFrame.parentStory.textContainers;

// loop over all text containers in order and collect those that are
// on your page
var textFramesInOrder = [];
for (var i = 0; i < textContainers.length; i++) {
  if(textContainers[i].parentPage === myPage) {
    textFramesInOrder.push(textContainers[i]);
  }
}

// now textFramesInOrder holds all the text frames of the page in correct order
mdomino
  • 1,195
  • 1
  • 8
  • 22