Create a component in the background layer

Hi guys,

I am not well verse with scripts and I have been struggling with the method to create components.

I would like to create a component of a specific glyphs in the background layer of other specific glyph. I am able to create a list of tuples in order to use a loop function like ‘for’.

My problem is creating the component. I have read the Glyphs API and this is how looks my script

iMatraList = [
(“iMatra_base-deva.00”, “iMatra-deva.00”),
(“iMatra_base-deva.01”, “iMatra-deva.01”),
(“iMatra_base-deva.02”, “iMatra-deva.02”),
]

print font.familyName
for iMatraCouple in iMatraList:
…matraBase, matraMask = iMatraCouple
…for layer in font.glyphs[matraBase].layers:
…layer.parent.beginUndo()
…layer.background.component(matraMask)
…layer.parent.endUndo()

I know that “layer.background.component(matraMask)” is not working, but somebody has a hit of how this could works? Thanks

First, you create the component.
comp=GSComponent(glyphname)

Then, you append it to the list of components of the background.
layer.background.components.append(comp)

Thanks Mekkablue