0

Using Indesign CS5.5, I have a vast collection of groups - all with an image and a textframe. The textframe has 3 paragraphs by default.

I need to get the text from the first paragraph of each textframe.

So far I have this:

var textboxes = app.activeDocument.groups.everyItem().textFrames;
for (i = 0; i <= textboxes.length; i++) { 
    if(textboxes[i] != 'undefined') {
        var product = textboxes[i].contents;
        $.writeln(product);
    }
}

This gives me ALL the text...I really need to get the first paragraph only OR filter it somehow by font size.

I've tried using textboxes[i].paragraphs[0], but this returns the rather vague Object Invalid. It might be a specific group, but it's too vague for me to tell.

Is there a way to skip and continue if an object is invalid. AND is there perhaps a way to only look for text with a certain font size?

Any help would be greatly appreciated. I find Indesign's scripting API documentation quite poor.

Funktion
  • 539
  • 2
  • 5
  • 16
  • Have you checked this question https://stackoverflow.com/questions/33467344/indesign-script-how-to-get-first-paragraph-in-threaded-text-frame ? – jontro Nov 03 '17 at 08:31
  • I did try bits of that, but not the `textContainers` - will try that. – Funktion Nov 03 '17 at 08:36
  • I can't use access textContainers in app.activeDocument. I should point out that the textframes are all separate and not part of any continuous story. – Funktion Nov 03 '17 at 08:40
  • the contents object might have more methods on it. Right now you're invoking toString implicitly – jontro Nov 03 '17 at 09:28
  • @jontro Does .contents invoke toString? I did try `.contents.paragraph` but that's not a recognised method or property I think. – Funktion Nov 03 '17 at 09:29
  • try `typeof contents` – jontro Nov 03 '17 at 09:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/158145/discussion-between-jontro-and-funktion). – jontro Nov 03 '17 at 09:34

1 Answers1

1

Suggest to use:

var m1stParas = app.activeDocument.groups.everyItem().textFrames.everyItem().paragraphs[0];

which should return an array of paragraphs (each element is a 1st para of each TF from each group)

So you will have a set of text objects. Each object.contents is a string.

In case of error "invalid object" - has your doc possibly empty textFrames in some groups?

Jarek

Cashmirek
  • 269
  • 1
  • 9