Help me on simple script

Hi All
Can anybody help me

MacroTab.title = "Point Counter"
font = Glyphs.font
# Get selected glyph
for layer in font.selectedLayers:
	glyph = layer.parent
	print("---------- %s ----------" % glyph.name)
	# count handles, nodes and paths
		
	for layer in glyph.layers:
		countPaths = 0
		countOffcurves = 0
		countCurves = 0
		countLines = 0
                
		for i, path in enumerate(layer.paths):
			countPaths += 1
			for node in path.nodes:
				if node.type == "offcurve":
					countOffcurves += 1
				if node.type == "curve":
					countCurves += 1
				if node.type == "line":
					countLines += 1

		countPoints = countCurves + countOffcurves + countLines
		countNode = countPoints - countOffcurves


		print("%s All - %s handles, %s Node, %s paths - %s" % (countPoints, countOffcurves, countNode, countPaths, layer.name) )
	print("")

I want add Glyphs.clearLog() but when I add everything clear and show nothing
and this code show node for all layer. I want just master layer
Thanks

The clearLog() is broken up. 3.3. I fixed it already and will update soon.

Thanks @GeorgSeifert
Do you have any suggestion for second part (Just master layer)

if layer.isMasterLayer:
    …

Thanks @mekkablue :pray:

1 Like

after update to 3301 clear log work but this script didnot work. what happend?
macro panel: File “”, line 5
NameError: name ‘glyph’ is not defined. Did you mean: ‘Glyphs’?

MacroTab.title = "Point Counter"
Glyphs.clearLog()
font = Glyphs.font
for layer in font.selectedLayers:
	print("---------- %s ----------" % glyph.name)
for layer in glyph.layers:
	if layer.isMasterLayer:
		countPaths = 0
		countOffcurves = 0
		countCurves = 0
		countLines = 0
		for i, path in enumerate(layer.paths):
			countPaths += 1
			for node in path.nodes:
				if node.type == "offcurve":
					countOffcurves += 1
				if node.type == "curve":
					countCurves += 1
				if node.type == "line":
					countLines += 1
		countPoints = countCurves + countOffcurves + countLines
		countNode = countPoints - countOffcurves
		print("%s All - %s handles, %s Node, %s paths - %s" % (countPoints, countOffcurves, countNode, countPaths, layer.name) )
	print("")
Traceback (most recent call last):
  File "<macro panel>", line 5
NameError: name 'glyph' is not defined. Did you mean: 'Glyphs'?

It works before
works on 3300

Your script doesn’t define the variable glyph.
You are declaring the variable layer twice: once as an iteration in Font.selectedLayers and once as an iteration in glyph.layers.

I would write:

for selection in Font.selectedLayers:
...
    for layer in selection.parent.layers:
    ...

Thank you @SCarewe :pray: