Help me with a script i am working on: Inserting #entry & #exit anchors

Tonight i watched TYPO Labs 2017 | Rainer Erich Scheichelbauer & Georg Seifert
https://www.youtube.com/watch?v=-lz3BRPWoWk

Rainer kept joking “im not much of a coder”… and often I feel like that atleast when it comes to unfamiliar territory of python scripting. However I continued working on a font and soon ran into a repetitive workflow that i figured I could solve with a macro. I gave it a shot and have a result pretty much as I wanted, expect for a small but important detail.

What I am missing is another subtractor within the variable “offsetExit”.
That would be the vertical stem weight that would be defined in the corresponding master.
As the exit must compensate by that amount.

I couldnt figure out how to access that.
Can anyone point me in the right direction?

Heres my macro

font = Glyphs.font

# get active layer
layer = font.selectedLayers[0]

# get glyph of this layer
glyph = layer.parent

print "Inserting entry and exit anchors in:"

# access all layers of this glyph
for layer in glyph.layers:
  name = layer.name
  print name
  
  thisLayer = font.selectedLayers[0]
  thisGlyph = thisLayer.parent
  thisGlyph.beginUndo()

  #define coordinates
  offsetEntry = layer.LSB
  offsetExit = layer.width - layer.RSB
  
  # add entry anchor
  layer.anchors['#entry'] = GSAnchor()
  layer.anchors['#entry'].position = NSPoint(offsetEntry, 0)
  
  # add exit anchor
  layer.anchors['#exit'] = GSAnchor()
  layer.anchors['#exit'].position = NSPoint(offsetExit, 0)

  thisGlyph.endUndo()

can you post a screenshot of the layer and what the result should be?

Access the vertical stems, and get the first value? Take a look at docu.glyphsapp.com.

But I don’t really understand what you are trying to do.

the macro adds 2 anchors entry and exit, the second one should before further left by the value of the vertical stem.

@rainer thanks for the link, but ofcourse i read the documentation and cant figure it out.

You could store the stem width in File > Font Info > Masters > Vertical Stems and then access it through:

firstMaster = Glyphs.font.masters[0]
firstStem = firstMaster.verticalStems[0]

yea i understand where the values are stored,
what i dont understand is the chain from the for loop of layer to get to the corresponding masters stem.

first master isnt helping in this case because the macro will iterate through all master layers.
how do u determing which master is the corresponding one?

i tried using masterID for this somehow but to no avail

Each layer has a associatedFontMaster() method (I’ll add it to the docs).

But I’m still not sure what you like to accomplish.

1 Like

thanks georg,
for anyone wondering heres the change

#define coordinate for
firstStem = layer.associatedFontMaster().verticalStems[0]
offsetEntry = layer.LSB
offsetExit = layer.width - layer.RSB - firstStem