Indesign script - How to get first paragraph in th

2019-09-11 17:17发布

问题:

I have a book with text frames on each page , they are all threaded together, I want to grab hold of each text frames first paragraph, is there any way, I'm trying app.activeDocument.textFrames[0].paragraphs.length and returns "0", only parentStory.paragraphs.length returns the paragraphs but I can't know which are the first in a text frame, any help?

回答1:

You should be able to use the textContainers attribute of Story to get each TextFrame of a story.

var frames = story.textContainers; // Where `story` is your story
for (var i=0; i<frames.length; i++) {
   var frame = frames[i];

   if (!frame.characters.length) continue; // Skip text frames without characters

   var para = frame.paragraphs[0];

   if (para.parentTextFrames.length > 1) {
      para = frame.paragraphs[1];
   }

   // Do work with `para` object
}


回答2:

The text frame's contents will have paragraphs.