Batch export

is there a way to export all open fonts to otf?

i tried a bit with the robofab way, but it doesn’t work.

A script like this should do the trick:

Exporter = NSClassFromString(“GlyphsFileFormatOTF”).alloc().init()
for f in Glyphs.fonts:
…print f
…Result = Exporter.writeFont_error_(f, None)
…print “Result:”, Result

thank you, georg.

this is btw something that could be better documented, i guess? no chance to get there without asking you explicitly for the code :slight_smile:

We are working on the documentation quite hard. But there is still a lot to do. We have to fine a way to make it better accessible.

i can imagine this. just wanted to point that out, as you asked for help on that. :slight_smile:

also: is that a typo, or supposed to be that:


? (found in the ‘print dir(Glyphs)’)

A lot if the stuff you see in the dir() output comes from the pyObjC (hint) bridge.

i meant, that i thought it could be a miss-spelling?

objcClass instead of ojbcClass

You are right. This comes from a library I use for something completely unrelated. Interesting find.

and is there a way to script the UFO export as well? For all open files, and the very best would be an option to keep the filename of the glyphs-file instead the family name (wanna generate versions as UFO)

i changed the script to GlyphsFileFormatUFO and get no errors, but the save dialog opens and ask me to name the file and where to put. so this is a) what i like to skip (or define in the script) and b) i don’t know if this creates a proper file?

Something like should get you started:

Exporter = NSClassFromString(“GlyphsFileFormatUFO”).alloc().init()
for f in Glyphs.fonts:
…print f
…Master = f.fontMasters()[0]
…FilePath = f.parent.fileURL().path()
…FilePath = FilePath.replace(".glyphs", “-”".ufo")
…Result = Exporter.writeUfo_toURL_error_(f, NSURL.fileURLWithPath_(FilePath) , None)
…print “Result:”, Result

wow, this works like a charm, thanks so much, will play around. the only thing is that it still exports only the lightes master, but you said already that you work on that (the general ufo export problem atm).

thank you, georg!

oh, i just realized that the first master is indexed in the script. works also with the second. nevermind, but thanks again :slight_smile:

Now I think of deriving a script, that exports WOFF and WOFF2, along with the @font-face CSS code. The latter bit I already got ready. So, but is it possible to reuse the NSClassFromString(“GlyphsFileFormatUFO”).alloc().init() in some way to call the Webfont exporter? Or in any other way?

Thanks in advance!

The webfont export is not scriptable at the moment. I worked on this but I’m not finished.

i’ll be patient, thanks!

Undusting this for something maybe related: Is it possible to access the Generate Instances via scripting? I am not seeking the instance method from the documentation here, but rather the ability to actually get the files ready for saving, with all the color labels etc. Basically exactly as the File > Generate Instances behaves.

BTW: is it on purpose, that a generated instance might end up with a different Master (weight) name than its original Instance (weight) name was? In particular I got a Font:
2 Masters (Regular [91], Bold [149])
2 Instances, same Names, same weight values, same weight declaration

When I generate the Instances, the new files end up like this:
One got Bold in Master and its Instance like expected, but the other one has now »Light« as its Master name, while its Instance is still »Regular« etc.

I assume the weight value might cause this? Anyway I am not sure if this should happen.

[quote=“Mark, post:17, topic:1383”]
BTW: is it on purpose, that a generated instance might end up with a different Master (weight) name than its original Instance (weight) name was?[/quote]

The one thing does not have much to do with the other. Does the Master name matter for what you want to do?

myInstance = thisFont.instances[0]
newFont = thisFont.interpolateInstance_error_(myInstance,None)

So what is the cause for this behaviour then? The master name matters indeed, that’s why I figured this issue. Basically I need single font files that represent the very instances for a certain script. At the moment I have to check all generated files if their (now) master names equal their (previous) instance names.