def executeAndReport(kernStrings): # brings macro window to front and clears its log: Glyphs.clearLog() Glyphs.showMacroWindow() # print status and modify Sample Texts: print("Adding %i lines to Sample Texts..." % len(kernStrings)) if not addToSampleText(kernStrings): print("Warning: could not add the lines.") else: print("Done.")
def SearchAndReplaceInAnchorNamesMain(sender): try: searchString = window.searchFor.get() replaceString = window.replaceBy.get() thisFont = Glyphs.font # frontmost font listOfSelectedLayers = thisFont.selectedLayers # active layers of currently selected glyphs for thisLayer in listOfSelectedLayers: # loop through layers thisGlyph = thisLayer.parent reportString = "Anchors renamed in %s:" % thisGlyph.name displayReportString = False for thisGlyphLayer in thisGlyph.layers: for thisAnchor in thisGlyphLayer.anchors: oldAnchorName = thisAnchor.name newAnchorName = oldAnchorName.replace( searchString, replaceString) if oldAnchorName != newAnchorName: thisAnchor.name = newAnchorName reportString += "\n layer '%s': %s > %s" % ( thisGlyphLayer.name, oldAnchorName, newAnchorName) displayReportString = True if displayReportString: print(reportString) if not SavePreferences(): print( "Note: 'Search And Replace In Anchor Names' could not write preferences." ) window.close() # delete if you want window to stay open except Exception as e: # brings macro window to front and reports error: Glyphs.showMacroWindow() print("Search And Replace In Anchor Names Error: %s" % e)