Created
March 11, 2019 18:58
-
-
Save frankrolf/a1284648a7cc05af3cda1414ee2a5396 to your computer and use it in GitHub Desktop.
Robofont script for aligning selected points
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
# Simple align points script for Robofont. | |
# I have set this to shortcut ctrl-a | |
def average(coord_list): | |
coord_sum = sum(coord_list) | |
return int(round(coord_sum / len(coord_list))) | |
def distance(coord_list): | |
vList = [value for value in coord_list] | |
return max(vList) - min(vList) | |
g = CurrentGlyph() | |
g.prepareUndo('align points') | |
s = g.selection | |
xList = [] | |
yList = [] | |
for point in s: | |
xList.append(point.x) | |
yList.append(point.y) | |
for point in s: | |
if distance(xList) < distance(yList): | |
point.x = average(xList) | |
else: | |
point.y = average(yList) | |
g.update() | |
g.performUndo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amazing! Just what I needed.