Export file order

There is a way to force a specific order for the exports ?
For exemple export each Width Class one after another ?

I’m using a script and I sort my .ttf exported by creation date and I would like to keep the same order as my export panel in Glyphs.

Most of them are in the good order but few one are not.

The instances are exported concurrently. that means that they start ink order but might finish differently.

You could use a callback that is triggered just when the file was written but you get the original instance as an argument. So you know the original index.

Not sure to understand completely.
But it seems that this code, generate export one after each other, and keep the same order as the export panel in Glyphs.

exportFolder = 'CustomPath'
for instance in Glyphs.font.instances:
	instance.generate(FontPath = exportFolder, Containers = [PLAIN])

Glyphs exports fonts in parallel to complete the overall export more quickly.

In you script, fonts are exported in sequence which takes longer overall, but the creation date of the font files are in order.

1 Like

How do you use the sort order?

SelectedFolder = vanilla.dialogs.getFileOrFolder()
FolderPath = SelectedFolder[0]
SortedFolder = sorted(filter(os.path.isfile, os.listdir('.')), key=os.path.getmtime)

After that I’m using this list to display my files in UI

Here is a snippet that demonstrates the callback I was mention earlier:

class InstanceObserver (NSObject):
	def init(self):
		print("__", self)
		NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, "notifyExport:", "GSDocumentWasExportedNotification", None)
	def notifyExport_(self, notification):
		info = notification.object() 
		instance = info["instance"]
		print(instance, instance.font, instance.font.instances.index(instance))


This can be run from the macro window or a script. But it would be better off in a glyphPlugin.