Skip to main content
Known Participant
January 6, 2023
Answered

Why can't apply Character Style to Text Object in Illustrator 2021, 2023?

  • January 6, 2023
  • 2 replies
  • 1034 views

I attach sample data: Font2.ai

https://drive.google.com/file/d/1EZyR4TARjRAb9n7myCI9s2Oy8VD-wiCj/view?usp=sharing

 

Character style using a Composite Font.

This is my code:

var doc=app.documents[0];
var style=doc.characterStyles[1];
var oText=doc.textFrames[0];
style.applyTo(oText.textRange);

 

In Illustrator 2020: it apply ok,

But with Illustrator 2021,2023 thi occur error: an Illustrator error occurred: 285 ('')

 

Why can't apply Character Style to Text Object in Illustrator 2021, 2023?

This topic has been closed for replies.
Correct answer m1b

Hi @MrTran, I tried your code on your sample .ai document and I got the exact same results as you did. I don't think I'll be much help but here are two things I noticed:

1. The script actually worked (it applied the character style to the text), so if you put in a try/catch it won't show the error:

var doc = app.documents[0];
var style = doc.characterStyles[1];
var oText = doc.textFrames[0];
try {
    style.applyTo(oText.textRange);
} catch (error) { }

 

2. What is going on with that character style? The font family is "test2" which might not be right.

If I change "test2" to another font on my system, the script does not throw the error.

- Mark

2 replies

CarlosCanto
Community Expert
Community Expert
January 6, 2023

have you tried applying other composite fonts? 

 

I get the same 285 error but using a try/catch bypasses the error and it seems to apply the Character Style succesfully.

 

var doc=app.documents[0];
var style=doc.characterStyles[1];
var oText=doc.textFrames[0];
try {
    style.applyTo(oText.textRange);
}
catch(e) {/*$.writeln(e)*/}
MrTranAuthor
Known Participant
January 6, 2023

Thank you.

Yes, It only occur error with composite font.

 

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
January 6, 2023

Hi @MrTran, I tried your code on your sample .ai document and I got the exact same results as you did. I don't think I'll be much help but here are two things I noticed:

1. The script actually worked (it applied the character style to the text), so if you put in a try/catch it won't show the error:

var doc = app.documents[0];
var style = doc.characterStyles[1];
var oText = doc.textFrames[0];
try {
    style.applyTo(oText.textRange);
} catch (error) { }

 

2. What is going on with that character style? The font family is "test2" which might not be right.

If I change "test2" to another font on my system, the script does not throw the error.

- Mark

MrTranAuthor
Known Participant
January 6, 2023

Thank you.

1. I had try try catch, but it still can't apply to text object:

try {
style.applyTo(oText.textRange);
} catch (error) { }

 

2. Character style using a Composite Font, it is a font type of Japanese,

To create it refer: https://www.globalizationpartners.com/2016/03/09/illustrator-working-with-composite-font-for-japanese/

MrTranAuthor
Known Participant
January 6, 2023

Sorry, i had try again with try catch, it is ok.

Thank you, it can apply.