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?
Asked
Active
Viewed 1,442 times
0

P H
- 35
- 11
2 Answers
2
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
}

Josh Voigts
- 4,114
- 1
- 18
- 43
-
As a side note: this will work if OPs document is somehow set up to start every text frame with a fresh paragraph. If it starts with some text of a paragraph from an earlier frame, then *that* is "the first paragraph", even though it's at the bottom of a frame. – Jongware Nov 02 '15 at 22:20
-
@Jongware has a point, my paragraph might start from a previous frame, any idea how I can check if paragraph starts at beginning of text frame, or page (my text frame takes the whole page), and I will just loop through every paragraph in the story – P H Nov 03 '15 at 06:29
-
If I'm understanding you all correctly, you should be able to skip text frames without characters. That should prevent grabbing a paragraph from the previous frame. Also, if the first text frame has multiple parents, you can select the next paragraph which should be the first paragraph if it exists. What do you think? I updated the example. – Josh Voigts Nov 03 '15 at 15:42
0
The text frame's contents will have paragraphs.

user1754036
- 396
- 1
- 6
-
Unfortunately that is both true and not true - and may not be what the OP is looking for. True: the `contents` property of a textframe provides access to its paragraphs; *however*, it does so by converting the text to a Javascript compatible string. And through this you cannot manipulate InDesign's native Text objects (it's possible but disregards all formatting). As the OP does not go into detail on what should be done with the text, this may still work - but in general it's not a good idea. (Also, you don't provide a usuable snippet of code...) – Jongware Nov 02 '15 at 22:50