Advertisement
mekkablue

Glyphs.app: Guideline through Selected Nodes

Jan 31st, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #MenuTitle: Guideline through Selected Nodes
  2. # -*- coding: utf-8 -*-
  3. """Creates a guideline through the currently selected two nodes."""
  4.  
  5. import GlyphsApp
  6. import math
  7.  
  8. Font = Glyphs.font
  9. thisLayer = Font.selectedLayers[0]
  10. selection = thisLayer.selection()
  11.  
  12. if len( selection ) == 2:
  13.     firstPoint = selection[0]
  14.     secondPoint = selection[1]
  15.     xDiff = firstPoint.x - secondPoint.x
  16.    
  17.     myGuideline = GSGuideLine()
  18.     myGuideline.position = NSPoint( firstPoint.x, firstPoint.y )
  19.    
  20.     if xDiff != 0.0:
  21.         tangens = (firstPoint.y - secondPoint.y) / xDiff
  22.         myGuideline.angle = math.atan( tangens ) * 180.0 / math.pi
  23.     else:
  24.         myGuideline.angle = 90
  25.  
  26.     thisLayer.addGuideLine_( myGuideline )
  27.     thisLayer.setSelection_(NSMutableArray.arrayWithObject_(myGuideline))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement