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

Find and replace text SCRIPT

New Here ,
Feb 21, 2019 Feb 21, 2019

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
10.2K
Translate
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];
    

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

Sorry about my typos. I was typing to fast

Translate
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

Give an example *.AI file for testing please.

Translate
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

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

..

Translate
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

Salut

remplacer "\r" par quoi ?

LR

Translate
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

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"

Translate
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

Salut !

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

Change Line-Breaks in Paragraphs by GREP/regex

Bon courage

LR

Translate
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

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; 

               } 

      } 

Translate
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

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?

Translate
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

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.

Translate
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

Je te donne la solution

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

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

de elleere

Translate
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

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

Translate
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

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

Translate
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

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

Translate
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

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

Translate
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

To make the script work again, just replace this line

this_text_frame = text_frames;

with this line

this_text_frame = text_frames[i];
Translate
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
LATEST

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

Translate
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