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

Change a font using extendscript in illustrator

Explorer ,
Aug 06, 2014 Aug 06, 2014

Copy link to clipboard

Copied

I have a script that loops through text items on an illustrator page and when it encounters one of a certain size it changes it to a different point size. I would also like to alter the font. The code I have is

     if (roundedSize== 7.2) {

                item.textRange.characterAttributes.size=9.6;

                $.writeln(item.textRange.characterAttributes.textFont)

                item.textRange.characterAttributes.textFont="Metric-Semibold"

                };

It work fine without the fourth line, but as soon as I try and set a typeface the loop bails. Could someone tell me what I am doing wrong here

Many thanks

TOPICS
Scripting

Views

5.7K

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
Adobe
Community Expert ,
Aug 06, 2014 Aug 06, 2014

Copy link to clipboard

Copied

Hi Bob Haslett,

there are several ways.

One way could be:

item.textRange.characterAttributes.textFont = textFonts.getByName("Metric-Semibold");

Have fun

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
Explorer ,
Aug 07, 2014 Aug 07, 2014

Copy link to clipboard

Copied

Thanks tha works just as I want it to.

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
Explorer ,
Apr 06, 2018 Apr 06, 2018

Copy link to clipboard

Copied

Thanks for this solution. I have tried using this, but I get error

var doc = app.activeDocument;

ii= doc.textFrames.add();  //adding text

ii.textRange.characterAttributes.size = 9.5;  //character size for text

ii.textRange.characterAttributes.textFont = app.textFonts.getByName("Times");

ii.contents="wwwwww";

I would be grateful for any suggestions.

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 ,
Apr 06, 2018 Apr 06, 2018

Copy link to clipboard

Copied

Some notes:

Define your variable for the textFrame (eg var ii = doc... )

Do better not use ii as variable name. This is mostly a 'counter variable'.

Times is not a valid textFont name. Use Times-Roman or Times-Bold instead.

Have fun

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
Explorer ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

Thanks a lot, It worked..

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
New Here ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

Can you show the complete code for the above requirement  ?

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
Guide ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

LATEST
var doc = app.activeDocument;
var text1 = doc.textFrames.add();
text1.textRange.characterAttributes.size = 9.5;
text1.textRange.characterAttributes.textFont = app.textFonts["TimesNewRomanPSMT"];
text1.contents = "wwwwww";

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