Delete brace layers with a specific name

I have a brace layer with a specific name for multiple glyphs in a font. At some point I’ve decided to create a separate master for this style. Now I need to delete all {Black 180} layers. There must be something in Python that would do the trick.

I know there is Rainer’s script “Find and Replace in Layer Names”, I assume this may serve as a good starting point for the script that would do that, but I have no idea or experience in successfully modifying python scripts.

Any help would be very much appreciated!

(just typed in Safari)

layerName = "Black {180}"
for glyph in Font.glyphs:
    layer = glyph.layers[layerName]
    if layer:
        glyph.remove(layer)

Thank you, Georg!
I’ve tried it in Macro panel - doesn’t work :frowning:
Anything I’m missing?

You might need to adjust the layerName?

The name is fine, I’ve checked… :thinking:

Which error message do you get?

No error. It just doesn’t do anything. No matter how many glyphs are selected - one or all

Oh, sorry, it does say:
Traceback (most recent call last):
File “”, line 5, in
AttributeError: ‘GSGlyph’ object has no attribute ‘remove’

sorry. This should work.

layerName = "Black {180}"
for glyph in Font.glyphs:
    layer = glyph.layers[layerName]
    if layer:
        glyph.layers.remove(layer)

It does! Thank you so much, Georg!

And did you copy all those layer into the master? This could have been done with a scriptm too.

I simply used Instances -> “Instance as Master” so I don’t really need to copy them now. On the other hand, it should be very useful in the future - if it’s not too much to ask, can you tell me how to do it?

layerName = "Black {180}"
master = font.masters[XXX]
for glyph in Font.glyphs:
    layer = glyph.layers[layerName]
    if layer:
        glyph.layers[master.id] = layer

the second line needs to set the master with whatever master you need.

Thank you, Georg! I’ll give it a try!