Re-interpolate Metrics with script


is there already a script, that “re-interpolates Metrics” of all brace layers at once?
I guess it might be written within two minutes, but I can’t script :see_no_evil:

Right now I am opening all glyphs with “New Tab with all Brace Layer” and select all brace layers manually to re-interpolate matrice. I think this could be perfectly done with a script within seconds instead of one hour.

Thanks and have a happy Sunday/Holiday!

In one hour you can learn basic scripting so far that you can build the loop. Read through the scripting tutorials, parts 1 and 2:

If the layer is a bracket or brace layer, its .isSpecialLayer attribute will be True. And then you can hang the .reinterpolateMetrics() method.

1 Like

Hi Rainer,

finally, I tried do the script. I took your existing script “New Tab with Special Layers” and modified it, but it doesn’t work as expected. Basically, I just replaced the “newTab” function with “reinterpolateMetrics”.

Within the Makro Window, I get this error:

Traceback (most recent call last):
File "<macro>", line 19, in <module>
AttributeError: 'NSKVONotifying_GSFont' object has no attribute 'reinterpolateMetrics'

This is the script right now, I have no idea why the function doesn’t work.

#MenuTitle: Reinterpolate Brace Metrics
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals
Reinterpolates Metrcis of all special (bracket & brace) layers.

Glyphs.clearLog() # clears log of Macro window
thisFont = Glyphs.font # frontmost font
affectedLayers = []
for thisGlyph in thisFont.glyphs: # loop through all glyphs
	for thisLayer in thisGlyph.layers: # loop through all layers
		# collect affected layers:
		if thisLayer.isSpecialLayer: 

# Reinterpolate Brace Metrics:
if affectedLayers:
	reinterpolateMetrics = thisFont.reinterpolateMetrics()
	reinterpolateMetrics.layers = affectedLayers

# otherwise send a message:
		title = "Nothing Found",
		message = "Could not find any bracket or brace layers in the font.",
		OKButton = None

Any help is really appreciate. My current typeface has to many Brace Layers to do it by hand…

Thanks a lot :slight_smile:

You must call reinterpolateMetrics on a GSLayer object. While you iterate through layers, you can just call that on every one for which isSpecialLayer is True

Thanks for your answer. It will take another six months to understand that :smiley:

It’s all in the first part of Rainer’s script, you don’t need the rest:

for g in Font.glyphs:
  for l in g.layers:
    if l.isSpecialLayer:

Try this :wink:

No idea what /g and /l means, but it works. Thank you very very much. This helps a lot and makes the production way more faster.

Merci Beaucoup!!!

You should read up on variables and loops. That is the very basis of scripting.