In the 1086, the script I am relying on (heavily) stopped working. Here’s the code below. If you have glyphs X Y Z and firstDestinationName is A, then the three glyphs moves to A B C. But in 1086, it doesn’t work and deletes the glyphs instead. Could you find the reason why, or revise the code, or let me go back to 1084?
f = Glyphs.font
sel = f.selectedLayers
firstDestinationName = "A" #glyph name of the first letter of the destination group
# g0 = source glyph, g1 = destination glyph
if firstDestinationName not in (None, ""):
g0Names = [l.parent.name for l in sel] # source glyph names
if len( firstDestinationName ) == 1: # convert unicode to glyph name
firstDestinationName = Glyphs.niceGlyphName(firstDistinationName)
for i, g in enumerate(f.glyphs): # find index of first g1
if firstDestinationName == g.name:
g1Pos = i
g1 = f.glyphs[firstDistinationName]
break
g1Names = [f.glyphs[i].name for i in range(g1Pos, g1Pos+len(sel))]
g1Refugees = [ f.glyphs[i].copy() for i in range(g1Pos, g1Pos+len(sel)) if f.glyphs[i].name not in g0Names]
g0FreeNames = [ n for n in g0Names if n not in g1Names ]
for g in g1Names:
if g not in g0Names:
del(f.glyphs[g])
for i, n in enumerate(g0Names):
g0 = f.glyphs[n]
g0.name = g1Names[i]
for i, g1 in enumerate(g1Refugees):
g1.name = g0FreeNames[i]
f.glyphs.append(g1)
for g in f.glyphs:
g.updateGlyphInfo()
for g in f.glyphs:
if len(g.name) > 4:
if g.name[-4:] == '.001' and f.glyphs[g.name[:-4]] == None:
There seems to be a typo in firstDistinationName instead of firstDestinationName
After that updateGlyphInfo() fails while iterating so just iterated on names instead of glyphs like
for gname in [g.name for g in f.glyphs]:
glyph = f.glyphs[gname]
glyph.updateGlyphInfo()
Sorry the typo wasn’t there in the script. It was “Distination” all throughout and manually fixed it only here.
I’m getting an error at the “append” line saying that the glyph with the same name already exists. That should have been deleted prior but that’s being ignored.
In older versions like 2.4.4 this works as is, but in 2.5b (1086) it doesn’t update after the delete or rename so appending the new copy glyph fails. It works without disableUpdateInterface/enableUpdateInterface, but in 2.4.4 either way works the same.
Thanks, it’s handling better but still faulty. It complains that the glyph name “xxx” already exists in the font. It cannot be circumvented by disabling the interface update, so it’s more of dead end to me. It may be that Glyphs does not keep track of deleted glyphs.