• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

9.0K

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];
    

...

Votes

Translate

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

Copy link to clipboard

Copied

Sorry about my typos. I was typing to fast

Votes

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 Expert ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

Give an example *.AI file for testing please.

Votes

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

..

Votes

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

Votes

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"

Votes

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

Votes

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; 

               } 

      } 

Votes

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 Expert ,
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?

Votes

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.

Votes

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

Votes

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.

Votes

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...

Votes

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!

Votes

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

Votes

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
Guide ,
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];

Votes

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>

Votes

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