Skip to content

Instantly share code, notes, and snippets.

@connordavenport
Created February 7, 2023 16:26
Show Gist options
  • Save connordavenport/062996f1ea646ea67e0979974bc8b3b4 to your computer and use it in GitHub Desktop.
Save connordavenport/062996f1ea646ea67e0979974bc8b3b4 to your computer and use it in GitHub Desktop.
reorder a designspace file based on values
from fontTools.designspaceLib import DesignSpaceDocument
dspPath = 'path/to/file.designspace'
tempPath = dspPath.replace(".designspace","-reordered.designspace")
dsp = DesignSpaceDocument.fromfile(dspPath)
instanceMap = {}
for instance in dsp.instances:
instanceMap[instance] = tuple(instance.designLocation.values())
reordered = sorted(instanceMap.items(), key=lambda x: x[1])
dsp.instances = [inst for (inst,vals) in reordered]
dsp.write(tempPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment