Scripting: Array of glyph names

How can I access an array of glyphs names with python? I’ve attempted the following without success:

print Glyphs.font.glyphs['A, B, C']

print Glyphs.font.glyphs['A', 'B', 'C']

for glyphName in Glyphs.font.glyphs['A, B, C']:
    print glyphName

for glyphName in Glyphs.font.glyphs['A', 'B', 'C']:
    print glyphName
for glyphname in ['A', 'B', 'C']:
    print Glyphs.font.glyphs[glyphname]

Worked perfect. Thanks!

Edit:

How can I update metrics for the array of glyphs? For example, I tried the following but receive an error:

for name in ['B','E','F','K','N','P','R']:
    Glyphs.font.glyphs[name].leftMetricsKey = 'H'
    Glyphs.font.glyphs[name].syncMetrics()

Hi @Glypher,

syncMetrics() is a GSLayer method, not a GSGlyph method.

Try this:

for name in ['B','E','F','K','N','P','R']:
    Glyphs.font.glyphs[name].leftMetricsKey = 'H'
    for thisLayer in Glyphs.font.glyphs[name].layers:
       thisLayer.syncMetrics()

Thanks @Nicolas, that did the trick. I have one more question though…

How can this be applied for multiple blocks without repeating the syncMetrics portion?

For example:

for name in ['B','E','F','K','N','P','R']:
    Glyphs.font.glyphs[name].leftMetricsKey = 'H'
    for thisLayer in Glyphs.font.glyphs[name].layers:
        thisLayer.syncMetrics()

for name in ['C','G','Q']:
    Glyphs.font.glyphs[name].leftMetricsKey = 'O'
    for thisLayer in Glyphs.font.glyphs[name].layers:
        thisLayer.syncMetrics()

etc…

collect all glyphs that you changed and then run another loop

allGlyphs = set()

LeftMapping = {'H' : ['B','E','F','K','N','P','R'],
               'O' : ['C','G','Q']}

for key, names in LeftMapping.iteritems():
    for name in names:
        g = Glyphs.font.glyphs[name]
        g.leftMetricsKey = key
        allGlyphs.add(g)

for g in allGlyphs:
    for thisLayer in g.layers:
        thisLayer.syncMetrics()

1 Like

Excellent…thank you for the help Georg.