Edit *.glyph directly and see the change in editview tab immediately

Hi there,

I want to use python to edit *.glyph file in *.glyphspackage folder directly.
(for some batch processing, I hope to edit the raw files if it is possible.)

For example,

If 10th line in A.glyphs is (50,500,l),. (Denote a node coords and type in a shape).

I want to change it to (100,500,l),. My script would be:

import os

Glyphs.font.disableUpdateInterface()

file_path = "Myfont.glyphspackage/glyphs/A_.glyph"

with open(file_path, "r") as f:
	lines = f.readlines()
	
# print(lines[10]) #before: (50,100,l),
lines[10] = "(100,500,l),"
# print(lines[10]) #after: (100,100,l),

with open(file_path, "w") as f:
	f.writelines(lines)

Glyphs.font.enableUpdateInterface()

I’ve found the A.glyph has change immediately. However, the editview tab and Glyphs GUI window don’t. Only when I close the *.glyphspackage file and reopen it can see the change I made.

I’ve tried to use disableUpdateInterface() and enableUpdateInterface() function to freeze the GUI before I edited and refreeze it later. But they’re useless.

How can I edit *.glyph directly and see the change in editview window immediately? Is there any useful API functions and method?

Thank you.

The notification for changed files is not implemented (does matter if you do the change from within Glyphs or outside).

Why do you edit the file and not the position of the nodes?

something like:

glyph = Font.glyphs["A"]
layer = glyph.layers[0]
shape = layer.shapes[0]
node = shape.nodes[4]
node.position = NSPoint(100, 100)

(you need to change all those indexes to get to the node you like to change)

I’ve learned how to access each node and shape via Python before.

However, I have an idea about a git-based real-time synchronized plugin for collaborated working.

In git pull and git push processing, the *.glyph file in *.glyphspackage folder will be changed and overwritten directly.

Git uses file-based mechanism nor the Glyphs API. I have no idea how to apply the change on macro panel and so on.

If there’s no implement, I’ll think other non-git-based methods. Thank you!

You can load the .glyph file from the git repo and apply it’s content to the glyphs of the open font.