Delete all paths script

I had a script that simply deleted all paths in selected glyphs on the selected layer. Do not remember who is the owner or if I modified an existing script :woman_shrugging: but it did the job well. Now when I’m trying to run either this script or any other script from glyphs repository (different owners) that includes deleting paths (either on foreground or background layers), I’m getting this error message
TypeError: 'GSProxyShapes' object doesn't support item deletion
Here is the code I’m trying to get working:
Font = Glyphs.font
selectedLayers = Font.selectedLayers

def DeleteAllPaths( thisLayer ):
	thisLayer.parent.beginUndo()
	
	for i in range( len( thisLayer.paths ))[::-1]:
		del thisLayer.paths[i]
		
	thisLayer.parent.endUndo()

Font.disableUpdateInterface()

for thisLayer in selectedLayers:
	DeleteAllPaths( thisLayer )

Font.enableUpdateInterface()

Running it in the Macro window so there no import GlyphsApp etc in the beginning.
I know it looks very amateur, sorry about this. The last time I pretended to be a programmer/developer was 25 years ago in the uni.

1 Like
def DeleteAllPaths(thisLayer):
	thisLayer.parent.beginUndo()
	
	for i in range(len(thisLayer.shapes)-1, -1, -1):
		path = thisLayer.shapes[i]
		if isinstance(path, GSPath):
			del thisLayer.shapes[i]

	thisLayer.parent.endUndo()

Font.disableUpdateInterface()

for thisLayer in Font.selectedLayers:
	DeleteAllPaths(thisLayer)

Font.enableUpdateInterface()
1 Like

Thank you a million times Georg! Will give it a try!
Upd: Works like a charm!