The querstion of del(annotation)

I use del(annotation) for delete the annotation on every layer,but it not success,the annotation also has,and I try user layer.removeAnnotation(annotation),but it return “AttributeError: ‘GSLayer’ object has no attribute ‘removeAnnotation’” ,so how can I do it?Thanks!

Not sure why del() does not work. You could try this instead:

for annotation in layer.annotations:
   layer.annotations.remove(annotation)

del() works differently:

    del(layer.annotations[0])

You can use the ObjectiveC API directly but you need to replace the colon with an underscore:

    layer.removeAnnotation_(annotation)

(by looking at this, I found a problem with undo, that would crash Glyphs if you remove annotation with del().)

Thank you! It can do it!

I use the method that harbortype tall me it can do it, also thanks.
you can fix the bug later.

I try that:

for layer in g.layers:
	if layer.hasAnnotations:
		for i in range(len(layer.annotations)):
			del(layer.annotations[i])

It do it ,the annotation deleted,and not crash Glyphs

That’s what I used to do:

    for layer in g.layers:
    	if layer.hasAnnotations:
    		for an in layer.annotations:
    			del(an)

How can I write the code like yours in the grey area blocks?

You prefix it with three backticks like this: ```
I inserted them in your post, so you can check.

More about Markdown syntax

To remove all annotations, just do layer.annotations = None.

  a=b
  b=c
  if a==c:
    print True

thank you,I got it

Thanks,I need it better that you tell me