Skip to main content
Anantha Prabu G
Legend
February 26, 2017
Question

Find firstword of paragraph Lines

  • February 26, 2017
  • 2 replies
  • 1588 views

Hi All,

How to find the continue 3 same words in firstLine?

I tried the code 3 same words lastword of lines is working, but firstLine is not working.Please suggest friends

Code is here:

var myDoc = app.activeDocument;
var myLines_first = app.activeDocument.stories.everyItem().lines.everyItem().words.firstItem().getElements();
for (var i=0; i<myLines_first.length; i++)
{
    if(myLines_first.contents==myLines_first[i+1].contents && myLines_first.contents==myLines_first[i+2].contents)
    {
       var myResult = app.select(myLines_first)
        alert("stack word there")
        break;
     }
else
{
     alert("No stackwords found");
     exit();
}
}

Thanks,

Prabu G

This topic has been closed for replies.

2 replies

Obi-wan Kenobi
Legend
February 26, 2017

Hi,

You could try this:

var myDoc = app.activeDocument,

myLines_first = myDoc.stories.everyItem().lines.everyItem().words.firstItem().getElements(),

myCounter = 0;

for (var i=0; i < myLines_first.length-2; i++) {

    if (myLines_first.contents == myLines_first[i+1].contents && myLines_first.contents == myLines_first[i+2].contents) {

        var myResult = app.select(myLines_first);

        alert("Words Stack Here: \"" + myLines_first.contents + "\"\r(^/)  ;-)")

        myCounter += 1;

    }

}

if (myCounter == 0) alert("No Words Stack Found!\r(^/)  :(")

(^/) 

Anantha Prabu G
Legend
February 26, 2017

Hi Obi-wan Kenobi,

This worked perfectly! It was exactly the script I was looking for. Thanks so much, you're awesome!!!.

I need one clarification:  "myLines_first.length-2", why we use "-2"??

Thanks,

Prabu

Design smarter, faster, and bolder with InDesign scripting.
Obi-wan Kenobi
Legend
February 26, 2017

"-2" because you don't need to loop on "n-1" and "n" (targeted by "n-2")!

If you actually try, you'll get an error because "n+1" and "n+2" don't exist! 

(^/)

Jump_Over
Legend
February 26, 2017

Ananth@desgin  napisał(-a)

... but firstLine is not working ...

be more specific what "not working" does mean...

no result, wrong result, error?

Jarek

Anantha Prabu G
Legend
February 26, 2017

Hi Jarek,

Thanks for the reply. In above code show error message.

Thanks,

Prabu G

Design smarter, faster, and bolder with InDesign scripting.
Jongware
Community Expert
Community Expert
February 27, 2017

What error? Why don't you tell us?