Copy _corner glyph problem

The corner glyph is a wonderful function.
And we want to copy some different glyphs with corners to one glyph to make a new glyph. The following script is my test, but the corner in layer4 can’t copy right or lost.
Could you help ? We hope can copy them as we wish.

import copy

layer1 = Glyphs.font.glyphs['uni4E01'].layers[0]
layer3 =  Glyphs.font.glyphs['uni4E03'].layers[0]
layer4 =  Glyphs.font.glyphs['uni4E04'].layers[0]
layer5 =  Glyphs.font.glyphs['uni4E05'].layers[0]
layer =  Glyphs.font.glyphs['uni4E07'].layers[0]

layer.clear()

layer.shapes.extend(layer5.copy().shapes)
layer.hints.extend(layer5.copy().hints)
layer.shapes.extend(layer4.copy().shapes)
layer.hints.extend(layer4.copy().hints)
layer.shapes.extend(layer1.copy().shapes)
layer.shapes.extend(layer3.copy().shapes)

print("done")

corner.glyphs (12.6 KB)

Two small changes and it should work.

layer1 = Glyphs.font.glyphs['uni4E01'].layers[0].copy()
layer3 =  Glyphs.font.glyphs['uni4E03'].layers[0].copy()
layer4 =  Glyphs.font.glyphs['uni4E04'].layers[0].copy()
layer5 =  Glyphs.font.glyphs['uni4E05'].layers[0].copy()
layer =  Glyphs.font.glyphs['uni4E07'].layers[0]

layer.clear()
layer.hints = nil # clear() is not resetting the hints. I fixed that

layer.shapes.extend(layer5.shapes)
layer.hints.extend(layer5.hints)
layer.shapes.extend(layer4.shapes)
layer.hints.extend(layer4.hints)
layer.shapes.extend(layer1.shapes)
layer.shapes.extend(layer3.shapes)

print("done")
  1. you don’t need to import copy if you call the copy method. The copy module would be used like this: layer1 = copy(layer2). But calling the native method is better.
  2. When you assign the shapes and the hints from two different copies, the connection is lost. So make one copy and use it for both.

Or you could assign the glyphs as components and decompose them:

references = ("uni4E01", "uni4E03", "uni4E04", "uni4E05")

layer =  Glyphs.font.glyphs["uni4E07"].layers[0]

layer.clear()
layer.hints = nil # clear() is not resetting the hints. I fixed that

for reference in references:
	comp = GSComponent(reference)
	comp.position = NSPoint(10, 220) # pick a position if needed
	comp.automaticAlignment = False
	layer.shapes.append(comp)
layer.decomposeComponents()

print("done")

Wonderful!
But feedback NameError: the name ‘nil’ and ‘NSPoint’ is not defined.
What script should I add?
Thanks.

Sorry, I copied the wrong code.

from Foundation import NSPoint

references = ["uni4E01", "uni4E03", "uni4E04", "uni4E05"]

layer =  Glyphs.font.glyphs["uni4E07"].layers[0]

layer.clear()
layer.hints = None # clear() is not resetting the hints. I fixed that

for reference in references:
	comp = GSComponent(reference)
	comp.position = NSPoint(10, 220) # pick a position if needed
	comp.automaticAlignment = False
	layer.shapes.append(comp)
layer.decomposeComponents()

print("done")

Great!
Thanks a lot.