Glyph.layers.append() as first layer (= prepend layer)

Hi,

I am struggling to make the append() function actually push the new layer as the very first layer in the side panel. According to Glyphs API docs, layers is list, dict. Using insert doesn’t seem to work though.

Thanks for any pointers.

The layers property acts like a list (as you can append things) or a dictionary (you can access by layerID g.layers['id']. And you can also assign like to a dictionary. The master layers are the ones where layerID is the same as the id of the master. What you need to do is the following:

g.layers[font.masters[0].id] = layer

Thanks for the quick reply, @GeorgSeifert.

What I actually meant is insert the new layer as the first layer right AFTER the master layer = not to replace the master. Sorry for the confusion.

Here’s what I mean by a simple before/after:

The python API doesn’t all this. But the underlying core API does. You need to find the index of the previous or in the case the following layer and then use this:

glyph.insertObject_inLayersArrayAtIndex_(layer, index)