Access custom axes via API

I’m trying to get the variable font axes from a font master. .weightValue and .widthValue are easy, but how to get custom ones? .customValue somehow only works as it just returns the first custom one. According to the help on font master I see there are only 4 specific custom values: .customValue, .customValue1, .customValue2, & .customValue3

And then there is .customValueForKey_ but when I inject the axis name as the argument, I get None. I want to access it by it’s name if possible (because I cannot know how many custom axes are there.)

Thanks in advance :slight_smile:

Glyphs 2.x only supports those six.

Why not query master.customParameters["Axes"]?

Thank you, it also returns None. Do the master need another CP with the value?

I set up the axes in the Font Tab of the Font Info, and in the Masters I got the values on top, not in the masters CP. Is that wrong?

Sorry, not master, but font. So font.customParameters["Axes"].

That works, but it only gives me the name and tag. How do I get the master’s value for the custom axis? :slight_smile:

Well, then you know the order of the axis names (and tags). Then you can step through the following attributes of a GSInstance object:

  1. instance.weightValue
  2. instance.widthValue
  3. instance.customValue
  4. instance.customValue1
  5. instance.customValue2
  6. instance.customValue3

Edit: Ah, I see, you wanted master, not instance. Should be the same attributes though.

The .customValueForKey_ is to get the value of a custom parameter with that name. The customValue part has nothing to do with the interpolation settings. That is poor wording on my part.

Thank you, guys. What if I got more axes than .customValue3 covers. I see there is no .customValue4 and I said, for what I’m about to do, I can’t predict the amount of axes.

Georg explained it to me in person. No open questions so far :slight_smile: Thanks!

@Mark @GeorgSeifert I’d be interested to know how to do this as well. I’m writing a script which generates masters on the fly and would like to both add new axes to the Font via my script as well change the master axis values. I will end up with several axes.

Any help would be appreciated!

So it is basically like Georg and Rainer explained. What is not mentioned here but Georg told me is, that there are currently 6 axes possible. that’s why .customValue stop here at .customvalue3

To add an axis:

axes = list(Font.customParameters["Axes"])
newaxis = {"Name":"some name","Tag": "some"}
Font.customParameters["Axes"] = axes
1 Like

I have added the axis to the python wrapper (will be available in version 1164).
Now you can do:

Font.axes.append = {"Name":"some name","Tag": "some"}

and to set the master axes:

master.axes[0] = 200
1 Like

That will bring some severe (to the good) changes I need to make in the Variable Font Preview plugin. But I’ll wait a bit, since you implemented it just recently. :slight_smile:

Will it support more than 6 axes then? So far I limited to 6 for now.

The six axis limit is not going to change in Glyphs 2.

Okay, no problem. Thanks :slight_smile:

I have recently been trying to access the custom values on the latter 3 axes, but keep getting this error:
AttributeError: 'GSInstance' object has no attribute 'customValue1'

Is this something that can be resolved by modifying the setup of the file or using a custom parameter? For reference I have gotten the same error in both the standard Glyphs App 2.5.1 and the Cutting Edge Version 2.5.2 (1163)

The instance had wrappers for the first three axis. I recently added an axes property. For older versions, you can use the not wrapped methods:


And to set a value:


Awesome, thanks!