How to delete nodes and keep the path open via Python?

Hi. I’m pretty new to Glyphs and I like it very much.

I’m trying to write a script to delete certain nodes to open a closed path, like we can do manually by Opt+Del or Cmd+X some nodes.
Could this be done by scripts?
Or do we have access to keyboard shortcuts via scripts?

Thanks in advance!

You would need to place the start node, and set path.closed=False, and the remove nodes either at the beginning or end of the path.

1 Like

There is a method layer.dividePathAtNode_(node).

2 Likes

Thank you @GeorgSeifert and @mekkablue!

I tried your advice with the following code.

nodes = Layer.selection
for node in nodes:
	path = node.parent
	Layer.dividePathAtNode_(node)
	path.removeNodeCheck_(path.nodes[0])
	path.removeNodeCheck_(path.nodes[len(path.nodes)-1])

It works well when I have only one node to delete for each path, but doesn’t work when there are two or more nodes to delete.
Do you have any suggestions?

I attach 3 images. The first one shows the 4 nodes I want to delete. The second one is the desired result and the third one is the result generated by the code above.

37
56
40

Layer.dividePathAtNode_(node) returns the second not on the split. This is the one you like to delete. And when you do the second split, there are two paths and you keep removing the nodes from the first path.

1 Like

Layer.dividePathAtNode_(node) returns the second not on the split.

Oh, I wasn’t aware of that.
Now it works great. Thanks!

nodes = Layer.selection
for node in nodes:
	path = node.parent
	this_node = Layer.dividePathAtNode_(node)
	second_path = this_node.parent
	second_path.removeNodeCheck_(this_node)
	path.removeNodeCheck_(path.nodes[len(path.nodes)-1])