HugoJ
(Hugo Jourdan)
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
SCarewe
(Sebastian Carewe)
March 31, 2023, 10:57am
2
The error message already explains what you need to do:
newMetric = GSMetricValue.alloc().init()
HugoJ
(Hugo Jourdan)
March 31, 2023, 11:02am
3
It seems that I can’t set an attribute using GSMetricValue.alloc().init()
AttributeError: can't set attribute
SCarewe
(Sebastian Carewe)
March 31, 2023, 11:04am
4
newMetric = GSMetricValue.alloc().init()
newMetric.position = 100
print(newMetric)
HugoJ
(Hugo Jourdan)
March 31, 2023, 11:08am
5
Only “position” and “overshoot” work.
All others produce an AttributeError.
HugoJ
(Hugo Jourdan)
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
(Hugo Jourdan)
April 7, 2023, 1:03pm
8
And how to add it to the font ?
master.metrics.append(new_metric)
This don’t work.
Hello,
Have anyone solved this problem?
I couldn’t find any clue about adding GSMetricValue to the master.metrics.
As HugoJ has mentioned, I can’t add GSMetricValue with ‘append()’ even though master.metrics is a ‘list’.
This thread is the only one I can find about master.metrics in this forum.
Thanks in advance.
What exactly are you trying to do. Add a new metric to the list or set the value for an existing one?
Hello,
I’d like to add a new metrics to the list.
(I have tested setting value for an existing one already and gotten successful result.)
Thanks,
Does this help?
from GlyphsApp import GSMetricsTypeBodyHeight
metric = GSMetric.new()
metric.type = GSMetricsTypeBodyHeight
Font.addMetric_(metric)
master = Font.masters[0]
metricValue = GSMetricValue.new()
metricValue.position = 800
metricValue.overshoot = 20
master.setMetricValue_forId_(metricValue, metric.id)
1 Like
or
type = GSMetricsTypeBodyHeight
name = None # or set a name
filter = None # or add a filter like "script == greek"
master.setMetricPosition_overshoot_type_name_filter_(800, 20, type, name, filter)
If there is a metrics with matching type, name and filter, it will overwrite it, otherwise it adds a new metric
1 Like
It is really helpful! I appreciate your support.
Dative
(Josse Pickard)
March 7, 2024, 4:18pm
15
@GeorgSeifert
Is there some way I can see a list of all possible the different type
classes?
For example how would I set the type
to “Other”?
HugoJ
(Hugo Jourdan)
March 7, 2024, 4:21pm
16