Skip to content

Instantly share code, notes, and snippets.

@ryanbugden
Last active April 9, 2021 17:53
Show Gist options
  • Select an option

  • Save ryanbugden/e13fa4f24428a0f0aebeebe42c3d002c to your computer and use it in GitHub Desktop.

Select an option

Save ryanbugden/e13fa4f24428a0f0aebeebe42c3d002c to your computer and use it in GitHub Desktop.
# menuTitle : Add Guideline at Selection
# shortCut : shift+control+g
'''
If two points are selected, add an angled guideline along them.
If one point is selected, add a horizontal guideline there.
Ryan Bugden
2020
'''
import math
g = CurrentGlyph()
with g.undo("Add guideline at selection"):
if len(g.selectedPoints) > 1:
pts = []
for pt in g.selectedPoints:
pts.append((pt.x, pt.y))
if pts[-1][0] == pts[0][0]:
g.appendGuideline((pts[-1][0], pts[-1][1]), angle=90)
else:
y_tri = pts[-1][1] - pts[0][1]
x_tri = pts[-1][0] - pts[0][0]
ang = math.atan(y_tri/x_tri) * (180/math.pi)
g.appendGuideline((pts[0][0], pts[0][1]), angle=ang)
elif len(g.selectedPoints) == 1:
pt = g.selectedPoints[0]
g.appendGuideline((pt.x, pt.y), angle=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment