How to get master stems horizontal or vertical separately

I saw older examples where it was possible to get master stems like this:

master.horizontalStems
master.verticalStems

But it seems like this doesn’t work anymore.
The newer examples (and also official documentation) only tells about this:

master.stems

But this way the stems are unnamed even if they have names in Font Info > Masters.
Is there a way to know which of stems is horizontal and which is vertical?

Thanks.

Look at the Font.stems list. It’s a list of GSMetric objects. From there, for each stem in the list, you can get the .name or check if it’s a .horizontal stem (bool, True or False). The name or orientation are stored on the GSFont level.

You should be able to use the same index number y of the list for the Font.stems to match the Font.master[x].stems[y] when pulling up the value on the master. You can also just use the name, e.g., Font.master[x].stems["Name"]

Hope that helps some.

1 Like

Thank you Jeff, this is the way!

font = Glyphs.font
master = font.selectedFontMaster

for i, stem in enumerate(font.stems):
	value = master.stems[i]
	if stem.name == "Vstem":
		print("VStem:", value)
	elif stem.name == "Hstem":
		print("HStem:", value)

that is not correct. Don’t rely on the names. Do it like this:

font = Glyphs.font
master = font.selectedFontMaster

for i, stem in enumerate(font.stems):
	value = master.stems[i]
	if stem.horizontal:
		print("HStem:", value)
	else:
		print("VStem:", value)
1 Like

Thanks Georg, I see the difference, it’s much more stable.