Skip to content

Instantly share code, notes, and snippets.

@weiweihuanghuang
Last active April 26, 2016 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weiweihuanghuang/c28ca190c71ba6b9a56d20ede0b448a1 to your computer and use it in GitHub Desktop.
Save weiweihuanghuang/c28ca190c71ba6b9a56d20ede0b448a1 to your computer and use it in GitHub Desktop.
#MenuTitle: Guideline through Selected Nodes
# -*- coding: utf-8 -*-
__doc__="""
Creates a guideline through the currently selected two nodes.
"""
import GlyphsApp
import math
Font = Glyphs.font
selectedLayer = Font.selectedLayers[0]
try:
# until v2.1:
selection = selectedLayer.selection()
except:
# since v2.2:
selection = selectedLayer.selection
if len( selection ) == 2:
firstPoint = selection[0]
secondPoint = selection[1]
xDiff = firstPoint.x - secondPoint.x
myGuideline = GSGuideLine()
myGuideline.position = NSPoint( firstPoint.x, firstPoint.y )
if xDiff != 0.0:
tangens = (firstPoint.y - secondPoint.y) / xDiff
myGuideline.angle = math.atan( tangens ) * 180.0 / math.pi
else:
myGuideline.angle = 90
selectedLayer.addGuideLine_( myGuideline )
selectedLayer.setSelection_(NSMutableArray.arrayWithObject_(myGuideline))
@mekkablue
Copy link

mekkablue commented Apr 26, 2016

closing parenthesis missing in L36
wrong indentation from L30 to the end

@weiweihuanghuang
Copy link
Author

weiweihuanghuang commented Apr 26, 2016

@mekkablue Whao that's weird...since the script used to work even like this. What should the indentation be?
Just tried it now with this new revision and it crashes right away,

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