100% accurate copy of a GSLayer

Hi there! Probably a question for @GeorgSeifert:

I’ve seen topics similar to this before, but I was confused about the solutions and I wasn’t sure if there was a formal ‘best answer’ to this, so I figured I’d post a new topic.

I want to copy the entire contents of a GSLayer to another GSLayer.

I need a literal 100% copy of a GSLayer, to another layer, preserving all data and allowing for all the methods to work.

For instance, hypothetically I’d like to be able to take the contents of the ‘Bold’ layer in the ‘A’ glyph, and copy it exactly into the ‘Bold’ layer for the ‘B’ glyph, assuming ‘Bold’ is a master and the layer is present in both glyphs.

Then I need to be able to decompose the components, for instance, in the contents of the ‘Regular’ layer of the ‘B’ glyph, which has just been copied.

What’s the best way to achieve this?

Thanks!

something like this:

boldMaster = Font.masters[1] # use the correct index
A = Font.glyphs["Adieresis"]
B = Font.glyphs["B"]
ABold = A.layers[boldMaster.id]
BBold = ABold.copy()
B.layers[boldMaster.id] = BBold

I’ll give this a try, thank you!