How to copy SmartComponentPoleMapping settings

I could copy the SmartComponentPoleMapping setting from layer to layer on the same file, however could not copy as a new glyph of an other file. The settings are not applied on the Glyph’s ‘Show Smart Glyph Settings’ dialog. How can I do that?

sourceFont = Glyphs.fonts[ indexOfSourceFont ]
sourceGlyph = sourceFont.glyphs[ thisGlyphName ]
sourcelayer = sourceGlyph.layers[ indexOfSourceMaster ]

targetFont = Glyphs.fonts[ indexOfTargetFont ]

newGlyph = GSGlyph(thisGlyphName)

for theaxis in sourceGlyph.smartComponentAxes :
	cpaxis = GSSmartComponentAxis()
	cpaxis.setName_(theaxis.name) 
	cpaxis.topValue = theaxis.topValue
	cpaxis.bottomValue = theaxis.bottomValue
	newGlyph.smartComponentAxes.append(cpaxis)
						
targetFont.glyphs.append(newGlyph)

for slayer in sourceGlyph.layers :
	newLayer = GSLayer(slayer.name)
	
	### Loop copy for paths and anchors

	mapping_str = str(slayer.smartComponentPoleMapping)
	mapping = dict([(i.split("=")[0], int(i.split("=")[1])) for i in re.sub(r'[\{\}\s\"\n]+', "", mapping_str).split(";") if "=" in i])

	for a in mapping.keys():
		newLayer.smartComponentPoleMapping[a] = slayer.smartComponentPoleMapping[a]

	targetGlyph.layers.append(newLayer)

Try setting the attributes after appending the new glyph to the font.

For example, I tried to change the position of appending a new layer like that, but the problem wasn’t improved

theID = 0
for slayer in sourceGlyph.layers :
	newLayer = GSLayer(slayer.name)
	targetGlyph.layers.append(newLayer)
	tlayer = targetGlyph.layers[theID]
	
	### Loop copy for paths and anchors

	mapping_str = str(slayer.smartComponentPoleMapping)
	mapping = dict([(i.split("=")[0], int(i.split("=")[1])) for i in re.sub(r'[\{\}\s\"\n]+', "", mapping_str).split(";") if "=" in i])

	for a in mapping.keys():
		tlayer.smartComponentPoleMapping[a] = slayer.smartComponentPoleMapping[a]
	
	theID += 1

Can you send me the complete script, please? Or do you have it on GitHub?