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.
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];
Copy link to clipboard
Copied
Sorry about my typos. I was typing to fast
Copy link to clipboard
Copied
Give an example *.AI file for testing please.
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
..
Copy link to clipboard
Copied
Salut
remplacer "\r" par quoi ?
LR
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"
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
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;
}
}
}
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?
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.
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
Copy link to clipboard
Copied
you did give me a solution and i am still trying to figure out how to make it work.
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...
Copy link to clipboard
Copied
Ya that worked like a charm. I did not recognize where to change thing.1 Thank you again!
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...
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];
Copy link to clipboard
Copied
OMG! Fast response, helpful answer! Thank you very much! <kneels in adoration>