Drawing nodes with python

Is there per chance any documentation / examples on path creation? I’m going a bit nutso with the basics…

/

f = Glyphs.font
g = f.glyphs[0].layers[0]

newPath = GSPath()
newPath.moveTo((100, 100))
newPath.lineTo((800, 100))
newPath.lineTo((100, 800))
newPath.closePath()

1 Like

You need to create and add nodes like this:

newNode = GSNode()
newNode.type = GSLINE
newNode.position = (100, 100)
newPath.nodes.append( newNode )

Best to put in a function and call it with a list of positions. Feel free to search my scripts for examples, e.g.:

Thanks Rainer!

I’m just curious why there’s two methods of drawing paths via scripts? One is the method used in @mekkablue’s script and documented in the Python Scripting API. And another in the Core which is what @lnp’s example was.

When would one use either?

There are differente use cases. If you just need to add a few nodes, it is easier to just add them. If you constantly convert between different outlines data formats, it might be a good idea to build you own pen (the format of the pen is explained in the Core page). Pens are explained on this page: http://www.robofab.org/objects/pen.html