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:
    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!

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

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.

Hi,

I was just trying to use this code again. But instead of generating UFOs, it just crashes GlyphsApp (cutting edge, as well as stable).
Do you know why? Is there a better way to do this now?

that is much easier now:

import os
for instance in Font.instances:
	instance.generate(UFO, os.path.expanduser("~/Desktop"))

There are two more options

  • UseProductionNames (default True)
  • DecomposeSmartStuff (default True)
	instance.generate(UFO, os.path.expanduser("~/Desktop"), UseProductionNames=False, DecomposeSmartStuff=False)
5 Likes

And I made a mistake in the original script:
the last line should have been:

ufoExporter.writeUfo_toURL_error_(instanceFont.masters[0], dest, None)
1 Like

Thanks Georg!
Is it possible to add the option to ZeroWidth the Marks, too?

1 Like

Yes please. Collapse the left sidebearing onto the right, make sure anchors stay in correct positions relative to outlines.

… Bump …

1 Like

Hopeful bump :smiley:

1 Like

I’ve written a script which takes care of that (and many other needed things), so ithe ufoExporter okay as it is, as for our former request here. Thanks! :slight_smile:

1 Like

Thanks Mark.

A general question for Georg…how can we know if you are also working on things that we need? In this case we really needed this functionality, and we asked about this nearly a month ago, but we didn’t get any response so Mark spent time writing this script. I don’t want him to have wasted that work, it’s not good for anyone to be duplicating work.

I might implement this at some point but specially with this stuff, where everyone has slightly different requirements, a script is a better solution as it is customizable.

1 Like

@GeorgSeifert Yes definitely. So true, please don’t jump on that train! There are a lot of conditionals involved already, way too much than a general tool could/should have)

1 Like