Skip to main content
New Participant
October 9, 2014
Question

reversing selected text or paragraph

  • October 9, 2014
  • 4 replies
  • 1743 views

hi all,

i have a document that contains the lines reversed (for example, Hello All is written llA olleH), so how can i reverse a selected line and reverse the text inside the line (assuming i select each line before i run the script), and also how can i reverse the whole document without needing to select every single line at a time?

thanks in advance

This topic has been closed for replies.

4 replies

Adobe Expert
August 12, 2023

Then use this version:

 

myLines = app.activeDocument.stories.everyItem().lines.everyItem().getElements();
for (i=0; i<myLines.length; i++) {
  s = myLines[i].contents.slice(0,-1);
  if (s.length > 2) {
    myLines[i].contents = s.split("").reverse().join("") + '\r';
  }
}

 

P.

Known Participant
August 12, 2023

Great Thanks for your effort peter

worked like a charm 

Adobe Expert
August 12, 2023

There was another line with the same problem:

 

app.select(myLines.characters.itemByRange(0, -2)); 

 

Add [i] after myLines

 

P

Known Participant
August 12, 2023

Thanks peter

Worked like a charm

Excuse me : How can i let script apply on whole document rather than selecting each page

Adobe Expert
August 12, 2023

In this line:

if(myLines.contents.match(/^\r/) !=null)

add [i] after myLines:

if(myLines[i].contents.match(/^\r/) !=null)
Known Participant
August 12, 2023

Nothing changed peter

Brainiac
October 9, 2014

#1: Selected Line or Paragraph

First select line or paragraph before running the code,

    myString = app.selection[0].contents;

    myString = myString.split("").reverse().join("");

    app.selection[0].contents = myString;

#2: for whole document

Try yourself:

//Logic

1. loop no. of pages

2. loop no of textframes

3. loop no. of lines

4. then paste the above code

5. thats it you're done.

Vandy

BEGINNER_X
Brainiac
October 10, 2014

Hi,

Hope you are new to scripting, so kindly use the below script.

With the help of vandy coding,

var myLines = app.activeDocument.stories.everyItem().lines.everyItem().getElements();

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

{

    if(myLines.contents.match(/^\r/) !=null)

    {

        continue;

        }

   

    app.select(myLines.characters.itemByRange(0, -2));

    alert("select line")

    myString = app.selection[0].contents; 

    myString = myString.split("").reverse().join(""); 

    app.selection[0].contents = myString; 

    }

Regards

Siraj

New Participant
October 10, 2014

Dear Sir,

Thank you for your reply,

The function ran correctly for couple of pages but we got the following error,

Kindly, do you have any solution?

Thank you in advance,