Export all instances to ufo


#1

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:
    ufoExporter.setFontMaster_(f)
    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?
Thanks!


#2

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:
		continue
	instanceFont = instance.interpolatedFont
	ufoExporter.setFontMaster_(instanceFont.masters[0])
	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


#3

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“?


#4

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


#5

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”?


#6

You could remove them from the font manually.


#7

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


#8

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


#9

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