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

Change a font using extendscript in illustrator

Explorer ,
Aug 06, 2014 Aug 06, 2014

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

Hi Bob Haslett,

there are several ways.

One way could be:

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

Have fun

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

Thanks tha works just as I want it to.

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

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.

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

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

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

Thanks a lot, It worked..

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

Can you show the complete code for the above requirement  ?

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