How to add new metric to a master with a script?

I want to add a new metric to a master using a script.

master = Font.selectedFontMaster

newMetric = GSMetricValue
newMetric.position = 100 = "Test"
newMetric.overshoot = 0
newMetric.filter = None
newMetric.metric = None


But this doesn’t work. It seems that I can’t use GSMetricValue() instead of GSMetricValue

TypeError: Use class methods to instantiate new Objective-C objects

The error message already explains what you need to do:

newMetric = GSMetricValue.alloc().init()

It seems that I can’t set an attribute using GSMetricValue.alloc().init()

AttributeError: can't set attribute
newMetric = GSMetricValue.alloc().init()
newMetric.position = 100


Only “position” and “overshoot” work.
All others produce an AttributeError.

I’m still struggling with this issue.
I have found some methods to set position, overshoot, and filter, but none to set the name.

font = Glyphs.font
master = font.selectedFontMaster

new_metric = GSMetricValue.alloc().init()

How do I set the name attribute and append new_metric to master.metrics ?

The name (and actually also the .filter) are stored in the GSMetricin font.metrics. You can get to the corresponding object:new_metric.metric` but only after you added it to the font.

1 Like

And how to add it to the font ?


This don’t work.