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

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

Community Beginner ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

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

Views

381

Translate

Translate

Report

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

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Thank you, it can apply.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

- Mark

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

I took too long to reply loll

 

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

 

applying characterStyles[0] or [2] works fine

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

[test2] is a composite font.

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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)*/}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you.

Yes, It only occur error with composite font.

 

Votes

Translate

Translate

Report

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