Skip navigation
Currently Being Moderated

Finding the end of line

Apr 23, 2012 12:08 PM

Is It possible to find and change a character in the end of each line from a block text?

I know Indesign GREP can't do this, GREP only finds the end of paragraph, not lines.

I understand this is a problem because every time the text frame is modified, you have another character being changed.

Is It possible to do this with a script?

I have attached an image of what I would like to do.

The text in the image is Hebrew (R2L language) and the end of line is in the left.

Any help would be great.

Sami

exemple.jpg

 
Replies
  • Currently Being Moderated
    Apr 23, 2012 12:36 PM   in reply to Sami Artur

    Well, if you've got some text (paragraphs, story, whatever):

     

    myText.lines.characters[-1]

     

    will get you the last character on the line.

     

    If you want to change what it is,

     

    myText.lines.characters[-1].contents = "Z"

     

    etc.

     

    Ariel

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 5:35 AM   in reply to Sami Artur

    It depends on how you're getting hold of the block of text.

     

    Let's say you select a paragraph in InDesign.

     

    So then  you can say:

     

    myPara = app.selection[0];

     

    then the lines in this paragraph are:

     

    myLines = myPara.lines;

     

    so now you can do a loop:

     

    for (var i =0; i<myLines.length; i++){

     

    now let's say you've set you app.findTextPreferences and app.changeTextPreferences to whatever you want, you can search the line as follows:

     

    myFinds = myLines[i].findText();

     

    and the last find on the line will be:

     

    myFinds[-1]

     

    so you can change that to whatever you want:

     

    myFinds[-1].contents = "Z";

    }

     

    If you want to substitute justification alternatives with regular letters it's obviously a little more complicated (you've got to find the unicode values, etc.) but this is the basic idea.

     

    One thing you've got to be careful about is that if you make a replacement, the lines shouldn't change. If the line breaks change, myLines will no longer be valid and you can get some weird results.

     

    HTH,

    Ariel

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 2:58 PM   in reply to Sami Artur

    Hi,

    Assuming your text is inside one or more text frames which are connected. Select one of them and run this:

     

    -------------

    myLines = app.selection[0].parentStory.lines;

    for (k=0; k<myLines.length; k++){

         if(myLines[k].characters[-1] == "\r")                         // if there is an end of paragraph

              myLines[k].characters[-2].contents = "z";          // change a second last character to "z"

         else myLines[k].characters[-1].contents = "z";     // otherwise change a last character to "z"

    }

     

    ------------

     

    This is just for show the way.

    Hope you step into

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points