Created
February 7, 2023 16:26
-
-
Save connordavenport/062996f1ea646ea67e0979974bc8b3b4 to your computer and use it in GitHub Desktop.
reorder a designspace file based on values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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