Batch export

Thanks so much!

And what are the arguments for saveToFile_error_(…, …)? I guess the second one can be None and the first might be filePath? All I tried spits depythonifying ‘pointer’ errors out.

And another related one: Is it possible to make use of anything alike the following but without closing all fonts?

Glyphs.closeAll_(Glyphs.fonts)

Indexing doesn’t do the trick and other closing functions cannot be found in the help(Glyphs).

There is a GSFont.close() method. It was missing from the docu. It accepts one parameter: ignoreChanges that controls if it asks to save changes.

Thanks Georg! That is some treat. Now I got the puzzle almost complete, only the last two pieces are missing from the yet open questions posted above [master name and saveToFile_error_()]. I would be grateful if anybody could help me out with these.

Hello there,
I am trying pretty much the same thing as Mark does with the UFOs, however, I wanted to change mine back to .otf files. When I change the code back, though, it does not export anymore and gives me “Result: 0”. What am I doing wrong? (as you can see, I am renaming the familyNames in the process, but that should not be a problem, should it?)

Oh, and I also had to comment out Exporter.setFontMaster_(Master), since it gave me an error when trying .otf. Is this the problem, maybe?

Exporter = NSClassFromString("GlyphsFileFormatOTF").alloc().init()
for i, f in enumerate(Glyphs.fonts):
    print f
    f.familyName = "myFamilyName" + str(i)
    Master = f.fontMasters()[0]
    #Exporter.setFontMaster_(Master)
    FilePath = f.parent.fileURL().path()
    FilePath = FilePath.replace(".glyphs", "-"+Master.name+".otf")
    Result = Exporter.writeFont_toURL_error_(f, NSURL.fileURLWithPath_(FilePath) , None)
    print "Result:", Result

Thanks in advance!

MD

Oh, and I am using Glyphs 1, since I am still on OS 10.8.5.

the OTF exporter has no fontMaster property. It always exports the first master, so you need to get an instance if you have more then one master.

this is not implemented. You can use this:

Exporter = NSClassFromString("GlyphsFileFormatOTF").alloc().init()
for i, f in enumerate(Glyphs.fonts):
    print f
    f.familyName = "myFamilyName" + str(i)
    Exporter.setFont_(f)
    FilePath = f.filepath.stringByDeletingLastPathComponent()
    Result = Exporter.exportToURL_error_(NSURL.fileURLWithPath_(FilePath), None)
    print "Result:", Result

You can’t set the actually filename of the font, it will be computed from the family and style name or set by a custom parameter.

So still no way to save the actual .glyphs file via script?

There is: GSFont.save('path')

While

thisFont = Glyphs.fonts[0]
thisFont.close()

works, unfortunately this one doesn’t work:

thisFont.save('WhateverPathWeTryHere')

–> AttributeError: ‘NSKVONotifying_GSDocument’ object has no attribute ‘typeName’

Any help please? .save('path') is not working here (s. a.). How to apply it, please? Using .save() without anything passed as parameter actually saves the font itself just fine, but I need to save it to a path, and this is exactly what doesn’t seem to work somehow.

While you’re talking about exporting…
Is it possible to make Glyphs remember the exporting location for each individual file. I’m working on different fonts at the same time and each time I’m exporting I have to change the folder…

I always export it into the Adobe Fonts folder and from there, in the finder (list mode, sorted by Date added), copy the fonts to the locations I need (usually more than one). If I need it very often, I set up a folder action.

1 Like

and the .save()? sorry for bumping.

Is there a way to access the production names in a script? That UFO batch export script is almost what I need, but how can I use production names in it?

What exactly does the script what the ufo-export can’t?
The UFO exporter can be configured to export with production names. Or, if you like to do it yourself you can ask the glyph for its productionName() (it is not in the wrapper, so it needs the parenthesis). If it is not set, use GSGlyphsInfo.productionGlyphNameForGlyph_(glyph).

The script batch exports all opened fonts as UFO, whilst the ufo-export only exports masters of a glyph file.
I would like to export instances as UFO with production names.

A)
Is the function generate() already implemented? I tried in the newest cutting edge and cannot make it work, neither given any errors.

B)
Would it be possible to generate as web fonts as well with it? If not, how to do that via code?

With doing the following, I always end up getting a .ttf no matter what FileType I specify:

for i, instance in enumerate(Glyphs.font.instances):
	if i == 0:
		instance.generate(["OTF"])

What is going on?

Do you have a custom parameter that forces TrueType?
I’ll have a look at the generate method.

Interesting Tipp. Unfortunately not. I even tried with a clean, new file. Same thing.