Skip to content

Instantly share code, notes, and snippets.

@frankrolf
Created March 11, 2019 18:58
Show Gist options
  • Save frankrolf/a1284648a7cc05af3cda1414ee2a5396 to your computer and use it in GitHub Desktop.
Save frankrolf/a1284648a7cc05af3cda1414ee2a5396 to your computer and use it in GitHub Desktop.
Robofont script for aligning selected points
# 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()
@hannaboslau
Copy link

Amazing! Just what I needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment