Is there a method to batch add brushes with Python?

Is there a method to batch add brushes with Python?

What exactly do you try to do?

I use the script to find the single line path that meets certain conditions in all characters, and then want to convert it into brush parts in batch with the function of ‘Add Brush’.
So I want to know s there an API interface for add brush that I can add in batches instead of clicking the right mouse button one by one to execute addbrush

path = Layer.shapes[0]
brush = GSHint()
brush.name = "_brush.test"
brush.type = 18 # should be BRUSH, just added it to the wrapper
brush.originNode = path.nodes[1]
Layer.hints.append(brush)

It’s good!Thanks!

this script does not work for the latest version, only having only one path appended, leaving others unchanged.
by the way, how to select all appended brushes, instead of one by one.

Can you explain a bit more. What is not working?

in the latest cutting edge version, press Cmd+A a few times.

屏幕快照 2024-04-02 上午3.56.18
only one path is appened with brush, the rest three unchanged.
sometimes, after applying the brush, new brushes will come out from nowhere.
屏幕快照 2024-04-02 上午4.01.21


Brush applied, it’s supposed to be ended. but, the script is trying to append more brushes on the selected (automatically selected, not by human).
屏幕快照 2024-04-02 上午4.01.39
a file about it attached
brush.glyphs (6.8 KB)
Glyphs 3251
Mac High Sierra 10.13.6

You need to use the oncurve node where the segment ends.