Add alignment zones in script?

Is it possible to add alignment zones in a script? I assume so (partly because of the addAlignmentZone function in the core API doc), but could you please help me undertand what syntax is required?

For example, I want to find the max Y point of my /Aring out of all masters, then add an alignment zone there, across all masters. I also want an alignment zone mirroring this, but below the baseline.

My overall script is like this (it’s not yet working):

font = Glyphs.font

# vertically centers bounding box on caps 
ascent = 2816
descent = -768

for master in font.masters:
  master.addAlignmentZone_([2816, 16]) 
  master.addAlignmentZone_([-768, -16]) 

The master.addAlignmentZone_ is erroring.

I’ve tried:

> master.addAlignmentZone_(2800, 16) 
> master.addAlignmentZone_(-752, -16) 

Which returned the error:

Traceback (most recent call last):
  File "<string>", line 14, in <module>
TypeError: Need 1 arguments, got 2

So, I then tried:

> master.addAlignmentZone_(2800) 
> master.addAlignmentZone_(-752) 

…which resulted in this error:

Traceback (most recent call last):
  File "<string>", line 16, in <module>
ValueError: NSInvalidArgumentException - -[OC_PythonNumber setParent:]: unrecognized selector sent to instance 0x600007d61a10

…and:

> master.addAlignmentZone_([2800, 16[) 
> master.addAlignmentZone_([-752, -16]) 

…which resulted in this error:

Traceback (most recent call last):
  File "<string>", line 16, in <module>
ValueError: NSInvalidArgumentException - -[OC_PythonArray setParent:]: unrecognized selector sent to instance 0x600007d16f30

How might I set these in script? Thanks for any tips!

1 Like

What do you like to have a zone at the same height in all masters. Zones are meant to control the overshot at common lines like the x-height.

To understand that you need to add as a zone you can print the existing zones. And have a look at https://docu.glyphsapp.com. There you find all you need. (a small hint: Font.masters[0].alignmentZones.append(GSAlignmentZone(2800, 10))

1 Like

What do you like to have a zone at the same height in all masters.

It’s hard to tell whether that is a question or not … To answer it if someone else comes along to read this, though, in some tests, it seemed that alignment zones seem to affect what is given as a default “bounding box” in macOS text rendering (in apps like Keynote, Sketch, TextEdit, etc – I believe this is ATS rendering). I’m not 100% sure whether this is the case, but it’s arduous to set alignment zones across 6 masters in the font I’m testing with, so I appreciate the scripting help!

Thanks, that works great!