HugoJ
March 31, 2023, 10:22am
#1
I want to add a new metric to a master using a script.
master = Font.selectedFontMaster
newMetric = GSMetricValue
newMetric.position = 100
newMetric.name = "Test"
newMetric.overshoot = 0
newMetric.filter = None
newMetric.metric = None
master.metrics.append(newMetric)
print(master.metrics)
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()
HugoJ
March 31, 2023, 11:02am
#3
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
print(newMetric)
HugoJ
March 31, 2023, 11:08am
#5
Only “position” and “overshoot” work.
All others produce an AttributeError.
HugoJ
April 7, 2023, 11:57am
#6
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()
new_metric.setPosition_(100)
new_metric.setOvershoot_(10)
print(new_metric)
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
HugoJ
April 7, 2023, 1:03pm
#8
And how to add it to the font ?
master.metrics.append(new_metric)
This don’t work.