Copying one glyph from one font to all layers in another

I’m trying to copy one glyph from one font to all layers of the current font.
I do this and doesn’t work (and couldn’t find a way yet):

notdefFont = Glyphs.open("/Path/to/my/font", showInterface=False)
gfont = Glyphs.font
for layer in gfont.glyphs['.notdef'].layers:
	layer = notdefFont.glyphs['.notdef'].layers[0]

Any hint? Thanks!

Which error do you get?

None, simply nothing happens…

Maybe the problem lies in the last line. You should add a .copy() at the end, otherwise you are referencing that object directly, which is connected to the other font’s GSGlyph. But what you want is probably an unattached GSLayer so you can hang it on the GSGlyph in the new font without conflicts.

I already had tried with .copy and didn’t work.
This, within the same font doesn’t work, with or without .copy:

gfont = Glyphs.font
for layer in gfont.glyphs['A'].layers:
	layer = gfont.glyphs['B'].layers[0].copy()

Bot scripts don’t do anything. You assigning a new object to a variable, that has no effect on the font where the layer that was assigned to that variable before.

This is how it could be done.

originFont = Glyphs.open("/Path/to/my/font", showInterface=False)
targetfont = Glyphs.font

if len(originFont.masters) != len(targetfont.masters):
	raise "The master count doesn't match"

originGlyph = originFont.glyphs['A']
targinGlyph = targetfont.glyphs['A']

for idx in range(len(originFont.masters)):
	originLayer = originGlyph.layers[idx]
	targinGlyph.layers[idx] = originLayer.copy()
gfont = Glyphs.font
aGlyph = gfont.glyphs['A']
bGlyph = gfont.glyphs['B']
for layer in bGlyph.layers:
	aGlyph.layers[layer.associatedMasterId] = layer.copy()

Thanks, will give it a try

It worked, thanks again.