Last active
March 7, 2016 13:47
-
-
Save mekkablue/c49da308adbf7f724b6d to your computer and use it in GitHub Desktop.
Tries to open the corner for a single selected node, in all layers if compatible.
This file contains 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: Open Corner in all Layers | |
# -*- coding: utf-8 -*- | |
__doc__=""" | |
Tries to open the corner for a single selected node, in all layers if compatible. | |
""" | |
thisFont = Glyphs.font # frontmost font | |
thisFontMaster = thisFont.selectedFontMaster # active master | |
thisLayer = thisFont.selectedLayers[0] # active layers of selected glyphs | |
selection = thisLayer.selection # node selection in edit mode | |
def findIndexOfNodeOnLayer( thisLayer, thisNode ): | |
for pathindex in range(len(thisLayer.paths)): | |
thisPath = thisLayer.paths[pathindex] | |
for nodeindex in range(len(thisPath.nodes)): | |
if thisNode == thisPath.nodes[nodeindex]: | |
return pathindex, nodeindex | |
return None, None | |
def openCorner( thisLayer, compareString, pathindex, nodeindex ): | |
try: | |
if thisLayer.compareString() != compareString: | |
print "Could not process Layer %s, because it is not compatible." % thisLayer.name | |
else: | |
thisNode = thisLayer.paths[pathindex].nodes[nodeindex] | |
if thisNode: | |
thisLayer.openCornerAtNode_offset_( thisNode, 20.0 ) | |
else: | |
print "Could not retrieve the same node on Layer %s." % thisLayer.name | |
except: | |
print "Could not open corner on Layer %s." % thisLayer.name | |
thisFont.disableUpdateInterface() # suppresses UI updates in Font View | |
if len(selection) == 1: | |
selectedNode = selection[0] | |
if type(selectedNode) == GSNode: | |
pathindex, nodeindex = findIndexOfNodeOnLayer( thisLayer, selectedNode ) | |
if pathindex is not None: | |
compareString = thisLayer.compareString() | |
thisGlyph = thisLayer.parent | |
thisGlyph.beginUndo() # begin undo grouping | |
for thisLayer in thisGlyph.layers: | |
openCorner( thisLayer, compareString, pathindex, nodeindex ) | |
thisGlyph.endUndo() # end undo grouping | |
else: | |
print "Could not find node and path index." | |
else: | |
Message("Select exactly one node", "This script only works with one node selected at a time.", OKButton=None) | |
thisFont.enableUpdateInterface() # re-enables UI updates in Font View |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment