Skip to main content
Known Participant
April 3, 2020
Answered

How to select next line of text, using GREP?

  • April 3, 2020
  • 2 replies
  • 2073 views

I use grep to search for linked images (~ a) and change the properties on that line, but I want to modify the text properties of the next line (the one highlighted in yellow) or in any case select the first word of the following line.

Thanks in advance.

This topic has been closed for replies.
Correct answer FRIdNGE

Easier to just do this rather than rely solely on GREP. 

app.findGrep returns an array of Character that you can then loop through to find containing paragraph and execute on the lines.  

 

 

 

 

//CLEAN GREP
app.findGrepPreferences = null;
app.changeGrepPreferences = null;

//GET FIND GREP
app.findGrepPreferences.findWhat="~a";
var myFinds = app.findGrep(true);

for (var i = 0; i < myFinds.length; i++) {
    try {
       myFinds[i].leading = 20;
       myFinds[i].baselineShift = -10;
       myFinds[i].paragraphs[0].lines[1].leading = 20;
   } catch(e) {
      continue;
   }
}

app.findGrepPreferences = null;
app.changeGrepPreferences = null;

 

 

 

 


Hi Brian!  😉

 

Change:

 

 

myFinds[i].paragraphs[0].lines[1].leading = 20;

 

 

by:

 

 

myFinds[i].lines[0].insertionPoints[-1].lines[0].leading = 20;

 

 

or, less greedy (only the first char of the next line):

 

myFinds[i].lines[0].insertionPoints[-1].lines[0].characters[0].leading = 20;

 

 

(^/) The Jedi 

2 replies

brian_p_dts
Community Expert
April 3, 2020

Do you expect the next line to always be the second line in the containing paragraph? If so, you can try looping through your finds like this: 

 

 

for (var i = 0; i < myFinds.length; i++) {
    $.writeln(myFinds[i].parent.paragraphs[0].lines[1].contents);
}

 

If you want the first word, you would append words[0] after lines[1]

 

Known Participant
April 3, 2020
//CLEAN GREP
app.findGrepPreferences = null;
app.changeGrepPreferences = null;


//find image and replace property of text  :
app.findGrepPreferences.findWhat="~a";
app.changeGrepPreferences.leading = 20; //INTERLINEADO
app.changeGrepPreferences.baselineShift  = -10;//DEZPLAZAMIENTO VERTICAL

app.changeGrep(true);


// find image and select next line 


app.findGrepPreferences = null;
app.changeGrepPreferences = null;

//what grep do i use here?

app.changeGrepPreferences.leading = 20; //INTERLINEADO
app.changeGrep(true);
Carpe diem
brian_p_dts
Community Expert
April 4, 2020

Michel__FRIdNGE_ a query, from my GREP search, how can I get the path of these linked images?


myFinds[i].pageItems[0].graphics[0].itemLink.filePath;
Willi Adelberger
Community Expert
April 3, 2020

Use for those paragraphs a style which has not a fixed value, use (auto).

Known Participant
April 3, 2020

Do you have a visible example of what you are saying?

Carpe diem
Willi Adelberger
Community Expert
April 3, 2020

Change the leading to (auto) in that paragraph style. Instead of something like 12 pt without paranthesis.