Copy and paste glyphs with scripting?

Can I copy a glyph from a font to another? I tried
destFont.glyphs.append( sourceGlyph.copy() )
but is not copied like if I copy and paste “manually”, it only appears grayed.

That is a bit complicated as you need to re-establish the connection with the masters:

target = Glyphs.documents[0].font
source = Glyphs.documents[1].font
sourceGlyph = source.glyphs["A"]
targetGlyph = sourceGlyph.copy()
targetGlyph.layers = {}
masterCount = min(len(target.masters), len(source.masters))

for i in range(masterCount):
	sourceMaster = source.masters[i]
	targetMaster = target.masters[i]
	sourceLayer = sourceGlyph.layers[]
	targetLayer = sourceLayer.copy()
	targetLayer.associatedMasterId =
	targetGlyph.layers[] = targetLayer


1 Like

Thanks, it worked perfectly!