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

[JS] Setting font of a textRange

New Here ,
Aug 27, 2008 Aug 27, 2008
Hi

In Ai CS3, I am trying to set the font of an entire textFrame, using this type of syntax:

newFrame.textRange.characterAttributes.textFont.family = "Arial";

Either using 'family' or 'name', this produces no result whatsoever.
Anyone willing to shed light on me - why?

Cheerz,
Art
TOPICS
Scripting
1.7K
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 28, 2008 Aug 28, 2008
characterAttributes is Read Only according to the JS Reference.
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 ,
Aug 28, 2008 Aug 28, 2008
Hm...

If so, then what is the trick to set a font of a frame or a text range?

I have also tried a looped statement like this:
newFrame.textRange.character.characterAttributes.textFont.family = "Arial";

This produces no result either. :(
Artur
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
LEGEND ,
Aug 28, 2008 Aug 28, 2008
See the example given in the textFont object section of the CS3 Javascript Reference. Copy that script and run it. Then, change:

textArtRange = app.activeDocument.textFrames.textRange;

to:

textArtRange = app.activeDocument.textFrames.characters[0];

and run it again.

Then change:

textArtRange.characterAttributes.textFont = app.textFonts[0];

to:

textArtRange.characterAttributes.textFont = app.textFonts.getByName("Verdana");

and run it again.

You cannot always trust the name that is displayed in AI's font menu as the actual name of the font. For example, on my machine, the font listed as "Arial" is actually named "ArialMT".

JET
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 ,
Aug 29, 2008 Aug 29, 2008
LATEST
Noooow you got me working :)
Thank you. Indeed, the font names got fancy sometimes.
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