Copy link to clipboard
Copied
I have a textframe and I want to replace the text content.
Here is my code
var doc = app.open(new File("D:\\test.ai"));
var layers = doc.layers
layers[0].textFrames[0].contents = "عنب كرز"
previous font size is 12pt, after the operations, font size is 50pt, it's so strange!
font is HelveticaNeueLT Bold
1 Correct answer
@LoveYou阿逗逼6666, you could try something like this:
var doc = app.open(File(File($.fileName).parent + '/SUPPLIED/test.ai'));
var text = doc.layers[0].textFrames[0].textRange;
text.paragraphStyles[0].clear();
text.contents = "عنب كرز";
but it is actually altering the Paragraph Style and I think it might mess up your text. In my test, it changed the arabic—probably because of a setting needed in the style that I cleared. If you know the settings needed, we can set those with the script though.
...
Explore related tutorials & articles
Copy link to clipboard
Copied
I can't replicate the problem, possibly because I don't have Arabic enabled. Assuming it's a bug, you could just re-size.
var size = layers[0].textFrames[0].textRange.size;
layers[0].textFrames[0].contents = "عنب كرز";
layers[0].textFrames[0].textRange.size = size;
Copy link to clipboard
Copied
Hi @LoveYou阿逗逼6666, this is happening because of the interaction between your "Basic Paragraph" paragraph style and the way setting of "contents" works in scripting.
The quick answer is to redefine the "Basic Paragraph" style so it is 12pt (at the moment it is 50pt), or just change the text to NO style.
- Mark
Copy link to clipboard
Copied
how to redefine the "Basic Paragraph" style?
Copy link to clipboard
Copied
You can choose (A) "Redefine Style" in the Paragraph Styles panel (choose the equivalent for your language, if not English) which will make the paragraph style match the curent selected text style:
- Mark
Copy link to clipboard
Copied
I just want to change text content and avoid changing any text styles. how to keep the origin Paragraph Styles by jsx?
Copy link to clipboard
Copied
It seems that when we set the "contents" via a script, Illustrator inserts the new text using the non-overridden paragraph style, which is set to 50pt size.
Copy link to clipboard
Copied
@LoveYou阿逗逼6666, you could try something like this:
var doc = app.open(File(File($.fileName).parent + '/SUPPLIED/test.ai'));
var text = doc.layers[0].textFrames[0].textRange;
text.paragraphStyles[0].clear();
text.contents = "عنب كرز";
but it is actually altering the Paragraph Style and I think it might mess up your text. In my test, it changed the arabic—probably because of a setting needed in the style that I cleared. If you know the settings needed, we can set those with the script though.
If that doesn't help, the final thing would be to have your script apply a correct paragraph style. It often becomes important to fixing bad paragraph styles because of these kinds of problems.
- Mark

