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

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

Explorer ,
Jan 05, 2023 Jan 05, 2023

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?

TOPICS
Scripting
994
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

Community Expert , Jan 05, 2023 Jan 05, 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 s

...
Translate
Adobe
Community Expert ,
Jan 05, 2023 Jan 05, 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.

Screenshot 2023-01-06 at 17.09.44.png

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

- Mark

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
Explorer ,
Jan 05, 2023 Jan 05, 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-japanes...

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
Explorer ,
Jan 05, 2023 Jan 05, 2023

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

Thank you, it can apply.

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 ,
Jan 06, 2023 Jan 06, 2023

Thank you for the link. You have taught me something today.

- Mark

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 ,
Jan 05, 2023 Jan 05, 2023

I took too long to reply loll

 

anyway, it seems there might be something wrong with test2. 

 

applying characterStyles[0] or [2] works fine

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
Explorer ,
Jan 06, 2023 Jan 06, 2023

[test2] is a composite font.

I think, this is a bug of Adobe. Because with CC2020 can apply OK.

 

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 ,
Jan 06, 2023 Jan 06, 2023
LATEST

Yes it seems to be a bug. If you like you could lodge a bug. You can link the bug report to this thread, too.

- Mark

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 ,
Jan 05, 2023 Jan 05, 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)*/}
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
Explorer ,
Jan 05, 2023 Jan 05, 2023

Thank you.

Yes, It only occur error with composite font.

 

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