Updating custom variable axis across each master from script

I have a variable font with one custom axis, with its own ID and name, which appears in all of the masters I have created. I can set this value differently for each master in the app UI info panel. How can I do this from script?

I can find my axis when I look in font.axes so I can get its axisId and tag. But when I look in each of font.masters, how do I map that to the (I assume) externalAxes list? That just seems to be a list of numeric values. I’d like to basically be able to automatically assign a different value for my axis to each of the masters in the font.

Thanks!

Use GSFontMaster.axes. You can assing values by simply doing master.axes[0] = 100, for example.

Thanks. But how do I know which index in this list maps to the axis I’m trying to assign? I know my axis’s name and four letter code and i know how to turn those into an “id” but the id is an alphanumeric string, not an array index.

axis = Font.axisForName_("Weight")
axis_index = Font.axes.index(axis)

print(axis_index)

Have a look at the Method Reporter mekkablue script.

or do:

master[axisId] = 100

Very neat.

Perfect, thanks. (Assuming you mean master.axes[axisId]) FYI: the documentation here shows axes as deprecated, but that works, while externalAxesValues gets me a TypeError when I try this.

External axis values are not what you’re looking for. Those are the user-facing values in the exported variable font (i.e. the values of the “Axis Location” custom parameters). You are looking for internal axis values.