underscoretype/underscore-glyphs-scripts

collect all layers

Closed this issue · 1 comments

# For the first master, we transform the current tab content to that master

I would just go though all masters and collect all layers and only at the end, assign the layers to the tab.

# The layers of the text as initially in the tab

font = Glyphs.font
tab = font.currentTab

initialGlyphs = [l.parent for l in tab.composedLayers]

# Skip certain masters (in their order in the font info, first master 0)
# Eg: skipMasters = [1, 3, 5, 7] will skip the second, forth, sixth and eight masters)
skipMasters = []

newLayers = []
# Loop through all masters in the font
i = 0
for master in font.masters:
	if i in skipMasters:
		continue
	for g in initialGlyphs:
		newLayers.append(g.layers[master.id])
	newLayers.append(GSControlLayer(10))
	i += 1
tab.layers = newLayers

Cheers,
I had already noticed the non master layer issue, but the single update to the tab content is more efficient and readable, thanks for the suggestion — ended up with something close to the suggested code 👍