My script stopped working in 1086

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()

Then it all seems to work for me.

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.

Hmm, it worked for me a bunch of times with one file I tried. Not sure what’s different here.

@GeorgSeifert Looks like something changed in recent versions with disableUpdateInterface(). Not sure if it should be one way or the other.

Here’s a super simple version

font.disableUpdateInterface()
g1 = font.glyphs['A']
g2 = font.glyphs['B'].copy()
del(font.glyphs['B'])
g1.name = 'B'
g2.name = 'A'
font.glyphs.append(g2)
font.enableUpdateInterface()

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.

1 Like

I’ll have a look.

Please, this is crucial to my current project. I’m really looking forward to the fix :slight_smile:

Tosche, your script is not complete. I fixed the script from zakkuri, so i hope, yours will be fine, too.

Thanks! The incompleteness was only present in this post and not in the actual script I use (if you’re talking about “distination” spelling).

I just couldn’t run the script to see if it works, now.

I uploaded a new versions that should fix this.

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.