Find and replace text SCRIPT

New Here ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

I have been trying to find a scrip that will help me replace a Hard return. This will not work with the menu action. Is any one able to help me. Im not the greatest at coding, I know a little but not enough to right this.

TOPICS
Scripting

Views

7.4K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Feb 22, 2019 Feb 22, 2019

    lindseybock123  Réfléchir tu sais faire ?

Avec le script de CarlosCanto

// JavaScript Document for Illustrator
var active_doc = app.activeDocument;

var search_string = /\r/g; // g for global search, remove i to make a case sensitive search
var replace_string = String.fromCharCode(3); // pour "\n"

var text_frames = active_doc.textFrames;
var this_text_frame, this_text_frame;

if (text_frames.length > 0) {
    for (var i = 0 ; i < text_frames.length; i++) {
          this_text_frame = text_frames[i];
    

...

Likes

Translate

Translate
New Here ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

Sorry about my typos. I was typing to fast

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

Give an example *.AI file for testing please.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

I am not sure how to up load a file on here but im just trying to replace the line brake you get when you hit the "Enter" Button.

if you copy and past this in to a

AI file there will be a few in here

..

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

Salut

remplacer "\r" par quoi ?

LR

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

I would like to replace it with "\n" but does not need to be. Found some code that works but will not work with "\n"

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

Salut !

C'est l'inverse de ce que tu demandes...

Change Line-Breaks in Paragraphs by GREP/regex

Bon courage

LR

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

Code i found that will work

var active_doc = app.activeDocument; 

 

var search_string = /\r/gi; // g for global search, remove i to make a case sensitive search 

var replace_string = "~"; 

 

var text_frames = active_doc.textFrames; 

 

if (text_frames.length > 0) 

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

      { 

          var this_text_frame = text_frames[i]

           var new_string = this_text_frame.contents.replace(search_string, replace_string); 

            

           if (new_string != this_text_frame.contents) 

               { 

                    this_text_frame.contents = new_string; 

               } 

      } 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

this code seemed very familiar, so I searched and digged the original out of the grave

Re: Illustrator Find And Replace

are you good then? or do you still need help?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2019 Feb 22, 2019

Copy link to clipboard

Copied

That is the same code that i found. I am good with this I can make that work. If there is any chance you know how to make \n (Forced line break) I would be very grateful. I cant seem to get it to work. not sure what i am doing wrong.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 22, 2019 Feb 22, 2019

Copy link to clipboard

Copied

Je te donne la solution

     var s = /\r/g;     // motif pour pour "\r"

     var replacer = String.fromCharCode(3); // pour "\n"

de elleere

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2019 Feb 22, 2019

Copy link to clipboard

Copied

you did give me a solution and i am still trying to figure out how to make it work.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 22, 2019 Feb 22, 2019

Copy link to clipboard

Copied

    lindseybock123  Réfléchir tu sais faire ?

Avec le script de CarlosCanto

// JavaScript Document for Illustrator
var active_doc = app.activeDocument;

var search_string = /\r/g; // g for global search, remove i to make a case sensitive search
var replace_string = String.fromCharCode(3); // pour "\n"

var text_frames = active_doc.textFrames;
var this_text_frame, this_text_frame;

if (text_frames.length > 0) {
    for (var i = 0 ; i < text_frames.length; i++) {
          this_text_frame = text_frames[i];
          new_string = this_text_frame.contents.replace(search_string, replace_string);
          this_text_frame.contents = new_string;
    }
}

elleere LR Pour vous servir...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2019 Feb 22, 2019

Copy link to clipboard

Copied

Ya that worked like a charm. I did not recognize where to change thing.1 Thank you again!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 06, 2022 Jun 06, 2022

Copy link to clipboard

Copied

Hi! I am using Illustrator 26.2.1 Japanese on Windows 10 Pro 21H1 19043.1706. I saved this scrip as text file with extension .jsx, but it won't work, what am I doing wrong? Tried saving in both UTF-8 and ANSI to no avail. The following error appears:

 

Error 1302: No such element
Line: 13
-> new_string = this_text_frame.contents.replace(search_string, replace_string);

 

Hope there's still someone around to check this old thread...

スクリーンショット 2022-06-07 143628.jpg

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 06, 2022 Jun 06, 2022

Copy link to clipboard

Copied

To make the script work again, just replace this line

this_text_frame = text_frames;

with this line

this_text_frame = text_frames[i];

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 06, 2022 Jun 06, 2022

Copy link to clipboard

Copied

LATEST

OMG! Fast response, helpful answer! Thank you very much! <kneels in adoration>

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines