Export all instances to ufo


Hi, I’m trying to write a script that exports all font instances to .ufo, and I got stuck here:

ufoExporter = Glyphs.objectWithClassName_("GlyphsFileFormatUFO")
fontFilePath = Glyphs.font.filepath

for f in Glyphs.font.instances:
    folder = os.path.dirname(Glyphs.font.filepath)
    ufoFilePath = os.path.join(folder, f.fullName + ".ufo")
    dest = NSURL.fileURLWithPath_(ufoFilePath)
    ufoExporter.writeUfo_toURL_error_(f, dest, None)

I’m getting an error and I can’t find any documentation related.
Can you give some light?


You where close:

import os
ufoExporter = Glyphs.objectWithClassName_("GlyphsFileFormatUFO")
font = Glyphs.font
fontFilePath = font.filepath

for instance in Glyphs.font.instances:
	if not instance.active:
	instanceFont = instance.interpolatedFont
	folder = os.path.dirname(font.filepath)
	ufoFilePath = os.path.join(folder, font.familyName + "-" + instance.name + ".ufo")
	dest = NSURL.fileURLWithPath_(ufoFilePath)
	ufoExporter.writeUfo_toURL_error_(instanceFont, dest, None)

All the missing pieces are on docu.glyphsapp.com


Just curious: What is the advantage of doing this per script compared to using the Export option within Glyphs?
Is the script able to not export glyphs which are set as „do not export“?


Will do the same as generating all instances and then save it one by one as ufo. The normal ufo export only saves masters.


Okay, thanks for the info.

How would I go about if I want to export a UFO which does not include glyphs which are set to “don’t export”?


You could remove them from the font manually.


Hi! I’m trying to generate UFOs from a three master Glyphs file. Only one master is generating. Any idea why?


It exports all selected masters in File > Export > UFO.


I restarted Glyphs and got the panel where it allows me to select masters to export. It was missing before…weird.