Skip to main content
Inspiring
May 13, 2023
Question

Illustrator Javascript API?

  • May 13, 2023
  • 2 replies
  • 4995 views

I'm trying to finish a simple script for Illustrator that uses info about the font in a selected item.

I can't for the life of me find documentation about what information I could call on. I can't find an API documentation thingy. I've gone in circles on the adobe site (the developer site is terribly designed as far as that goes).

 

Wher would I look this up?

2 replies

Inventsable
Legend
May 13, 2023

Alongside what femkeblanco posted, I find most of Adobe's first party documentation really lacking and hard to navigate. There are community-created versions which are a lot more easily searchable and more modern which I use instead:

 

Inspiring
May 14, 2023

I would love it if someone here could help me figure out how to call for these things:

Font family name (separate)

Font style (bold/italic etc)

Variable font settings (if applicable)

 

I can't get these things into separate fields.

 

I made the script with ChatGPT. The ChatGPT Large Language Model struggles with finding or explaining these tags, and I struggle with the language to ask for it. 

So I went off to find the tags (if that's what they're called), and I've been through most of the pages mentioned above, searching for "font" and "type" but nothing clear came up. 

 

I'm ok with the script I have now, it suits my purpose, which is to speed up making shortlists for fonts when I'm working on something. 

 

But if one of you has an easier time teasing this information out of the data that you've pointed to, I'd love either the info itself or some help on how to find it.

 

I'm not a coder, I'd love to be but my attempts mostly fail without outside help. I tend to play around with obscure or badly documented things, plus my ADHD+ brain will end up in a ditch when I can't figure anything out, for too long. 

So I'm immensly grateful for any guidance.

 

And thanks for the help so far.

 

Sv.

Inventsable
Legend
May 14, 2023
// A selected textFrame, otherwise would be like app.activeDocument.textFrames[0]
var target = app.selection[0];

// This textFrame's attributes:
var attributes = target.textRange.characterAttributes

// This textFrame's font:
var font = target.textRange.characterAttributes.textFont
// could instead be: attributes.textFont

alert(font) // [TextFont MyriadPro-Regular]
alert(font.family) // "MyriadPro"
alert(font.style) // "Regular"

 

You'd want to reference these pages for what properties and methods are available:

 

ChatGPT isn't always reliable in scripting because it often misleads you entirely, confuses scripting between apps, or states certain methods exist inaccurately, and I've never actually used scripting alongside variable fonts to set or retrieve values but I'd imagine that those settings are most likely to be in CharacterAttributes.

femkeblanco
Legend
May 13, 2023

Go to https://developer.adobe.com/illustrator/.  Click "console" (in the upper right corner) and log in.  Click "Download resources".  Scroll down to "Illustrator", which is in the bottom half of the page.  Click "View downloads".  You'll find the JavaScript reference there.

 

Alternatively, go to https://assets.adobe.com/public/aa41975d-3a2b-4ba9-6658-34e88a029a63 (courtesy of @CarlosCanto).