Created
July 27, 2019 16:05
-
-
Save mekkablue/dce4eefb8211abfb58678673c9785211 to your computer and use it in GitHub Desktop.
Create Center Guideline
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
#MenuTitle: Create Center Guideline | |
# -*- coding: utf-8 -*- | |
__doc__=""" | |
Creates a guideline, horizontally or vertically centered between two selected nodes. | |
""" | |
Font = Glyphs.font | |
FontMaster = Font.selectedFontMaster | |
selectedLayers = Font.selectedLayers | |
selectedLayer = selectedLayers[0] | |
try: | |
# until v2.1: | |
selection = selectedLayer.selection() | |
except: | |
# since v2.2: | |
selection = selectedLayer.selection | |
def addAndSelectGuideline( thisLayer, originPoint, angle ): | |
"""Adds a guideline in thisLayer at originPoint, at angle.""" | |
try: | |
myGuideline = GSGuideLine() | |
myGuideline.position = originPoint | |
myGuideline.angle = angle | |
thisLayer.addGuideLine_( myGuideline ) | |
thisLayer.clearSelection() | |
thisLayer.addSelection_( myGuideline ) | |
return True | |
except Exception as e: | |
print e | |
return False | |
if len(selectedLayers) == 1 and len(selection) == 2: | |
thisLayer = selectedLayers[0] | |
thisGlyph = thisLayer.parent | |
firstNode = selection[0] | |
secondNode = selection[1] | |
centerX = ( firstNode.x + secondNode.x ) / 2.0 | |
centerY = ( firstNode.y + secondNode.y ) / 2.0 | |
guidelineOrigin = NSPoint( centerX, centerY ) | |
guidelineAngle = 90.0 | |
xDiff = firstNode.x - secondNode.x | |
yDiff = firstNode.y - secondNode.y | |
if xDiff < yDiff: | |
guidelineAngle = 0.0 | |
thisGlyph.beginUndo() | |
if not addAndSelectGuideline( thisLayer, guidelineOrigin, guidelineAngle ): | |
print "Error: Could not add guideline." | |
thisGlyph.endUndo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment