Tips on learning the Glyphs API

I’m trying to learn how to script Glyphs and comparing the tutorials and the API reference.
The goal is to be able to write scripts that do a set of actions, similar to how you’d run Photoshop “actions” on multiple images to create certain decorative letters.
I’ve managed to do the first step in one workflow, i.e. copy the glyph to a new component and make it an outline.

import copy

print(Font.selection[0].name)

for myGlyph in Font.selection:
	newGlyph = GSGlyph()
	newGlyph.name = myGlyph.name + ".0001"
	newGlyph.layers = copy.deepcopy(myGlyph.layers)
	for newPath in newGlyph.layers[0].paths:
		strokeWidth = 10
		newPath.setAttribute_forKey_(strokeWidth, "strokeWidth")
		print(newPath.parent)
	
	newGlyph.layers[0].flattenOutlinesRemoveOverlap_origHints_secondaryPath_extraHandles_error_(False,None,None,None,None)
	Glyphs.font.glyphs[newGlyph.name] = newGlyph

I found out about the function “flattenOutlinesRemoveOverlap_origHints_secondaryPath_extraHandles_error_” through searching the forums, but the “intellisense” in the Glyphs macro editor shows no such function and I don’t know where I’d otherwise have found out about it. Is there some other reference I’m not aware of?

One of the problems I’m trying to solve is to get the “inner shape” that you’ll get if you expand a fairly wide stroke on a shape and remove the outermost and innermost paths, any tips on how to do that with code?

I think I found one method at least.
I’ve been used to Java, didn’t think at first to use reflection like we have in Java.
The dir-method seems to work.

The editor is not sophisticated enough to show all available methods. The autocomplete has some manually added entries.

There are several tutorials about scripting: Learn — Search results for: ‘scripting’ | Glyphs
and the documentation: docu.glyphsapp.com
And for more details: You found dir() already. And you can have a look a the objectiveC headers in Glyphs 3.app/Contents/Frameworks/GlyphsCore.framework/Versions/A/Headers

Another script that might help you finding methods (sadly, not including documentation on how to use them): the Method Reporter script, you can find it in the mekkablue scripts available from the plugin manager.

1 Like

By the way, I found some broken links on the Plugin tutorial page.

It links to this page which gives me a 404.


Yes, the tutorial needs a few updates. Will take a few days though.