Clear selected glyphs in current master

Right now this code only clears the selected glyph in edit view. But I want to clear the selected glyphs in font view in current master. In the API it says I need to call selection but couldn’t manage it.

font = Glyphs.font
selectedLayer = font.selectedLayers[0]
for glyph in font.glyphs:
    if glyph.selected:
       selectedLayer.clear()

Also checked this script:

Here is a version for cleaning only layer of selected master.

#MenuTitle: Clear selected glyph 
# -*- coding: utf-8 -*-
__doc__ = """
"""

font = Glyphs.font
selectedMaster = font.selectedFontMaster

for glyph in font.glyphs:
	if glyph.selected:
		glyph.layers[selectedMaster.id].clear()
2 Likes

Thanks a lot!

You can make it even simpler like this. It will work in Font View or Edit View:

for layer in Glyphs.font.selectedLayers:
	layer.clear()

If you want it to only work in Font View you can do this:

if Glyphs.font.currentTab == None:
	for layer in Glyphs.font.selectedLayers:
		layer.clear()
1 Like