Indesign script - How to get first paragraph in th

2019-09-11 16:55发布

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?

2条回答
Luminary・发光体
2楼-- · 2019-09-11 17:26

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
}
查看更多
老娘就宠你
3楼-- · 2019-09-11 17:31

The text frame's contents will have paragraphs.

查看更多
登录 后发表回答