Skip to content

Instantly share code, notes, and snippets.

@weiweihuanghuang
Created June 7, 2016 14:26
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/cfe36653a618e331898f42995fcb0b2e to your computer and use it in GitHub Desktop.
Save weiweihuanghuang/cfe36653a618e331898f42995fcb0b2e to your computer and use it in GitHub Desktop.
Get All Components
#MenuTitle: Get All Components
# -*- coding: utf-8 -*-
"""Returns the selected text with all components available in each glyph"""
from AppKit import NSRange
Font = Glyphs.font
Doc = Glyphs.currentDocument
# Replace selected text
TextStoreage = Font.currentTab.graphicView().textStorage()
Range = TextStoreage.selectedRange()
editList = []
for l in Font.selectedLayers:
editList += ["/%s" % l.parent.name]
if len(l.components)>0:
for c in l.components:
editList += ["/%s" % c.componentName]
# Remove duplicates
def f7(seq):
seen = set()
seen_add = seen.add
return [ x for x in seq if not (x in seen or seen_add(x))]
editList = f7(editList)
# Sort editList according to file order
# editList = ["/%s" % g.name for g in thisFont.glyphs if "/%s" % g.name in editList]
editString = "".join(editList)
# Convert text string into character string
charString = Font.charStringFromDisplayString_(editString)
TextStoreage.replaceCharactersInRange_withString_(Range, charString)
# Set cursor at start of TextStorage
TextStoreage.setSelectedRange_(NSRange(0,0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment