Import Masters via API

Hello Glyphs team,

I am trying to import masters via API:

for importMaster in importFont.masters:
    font.masters.append(importMaster)
    newMasterID = importMaster.id
    for glyph in font.glyphs:
        importGlyph = importFont.glyphs[glyph.name]
        glyph.layers[newMasterID] = importGlyph.layers[newMasterID]
    font.kerning[newMasterID] = importFont.kerning[newMasterID]

In principle it works, but the metrics and stem widths of the imported masters are not set. I guess, they are stored outside of the master object? As my script is from 2018, are there other API changes to consider as well?

Thank you in advance.

They have to be set on the font level. This changed in Glyphs 3 to ensure compatible metric and stem setups.

Look at GSFont on docu.glyphsapp.com, e.g.:

There is a method that handles this. So your script would look like this:

for importMaster in importFont.masters:
    font.addFontAsNewMaster_(importMaster)
1 Like

Great! Thank you.