Tutorial-Script gives unexpected output

Hello,
I am trying to get into scripting in Glyphs and started with the Tutorials on the website.
However the first one already confuses me a little.

There is this script:

myLayers = Glyphs.font.selectedLayers
for thisLayer in myLayers:
    print( thisLayer.parent.name )
    print( thisLayer.paths )

and it is supposed to give an output like this:

A
(<GSPath 57 nodes and 29 segments>, <GSPath 10 nodes and 4 segments>)
B
(<GSPath 53 nodes and 23 segments>, <GSPath 42 nodes and 16 segments>)
C
(<GSPath 57 nodes and 23 segments>)

If I copy/paste this script now from the tutorial page and run it in the makro window myself i get the following output:

m
<GSProxyShapes: 0x6000094c4200>
n
<GSProxyShapes: 0x6000094c4ee0>

So, is there something I did wrong? Or did things change in how you access information with a script?

This is a difference between Glyphs 2 and Glyphs 3. In Glyphs 2, layer.paths was a list of GSPath objects. However, a layer can also contain components. So if you loop over layer.paths you are ignoring the components (if there are any on the layer).

In Glyphs 3, the shapes of a layer (paths and components) are stored in layer.shapes. Loop over this value to get both the paths and the components in the order in which they occur on the layer.

In case you are only interested in the paths of a layer and not its components, the layer.paths property still exits in Glyphs 3. However, it is now a proxy object (GSProxyShapes) that does not store the paths itself. Instead, it just refers to the paths that are in layer.shapes. You can still loop over layer.paths, but for other modifications like inserting a new path, use layer.shapes.

1 Like

Thanks, that makes things a bit clearer for me :slight_smile:

Maybe a note in the tutorial part would be helpful? Especially if you expect a lot of people working with G2 and G3

The tutorials need to be rewritten. On my list. But don’t know when exactly yet.