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.


#10

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?


#11

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)

#12

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

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

#13

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


#14

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


#15

… Bump …


#16

Hopeful bump :smiley:


#17

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:


#18

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.


#19

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.


#20

@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)