Hi, I used to have a script that was working, but it isn’t anymore.
For some reason when it comes to an open path it does not recognise its last node (index -1) making it a NoneType object.
Hi, I used to have a script that was working, but it isn’t anymore.
For some reason when it comes to an open path it does not recognise its last node (index -1) making it a NoneType object.
Can you show the code. Do you know in what version of Glyphs it did work?
Ditto, but I don’t remember the last version which worked.
print(Layer.shapes[0].nodes[-1])
returns None.
I don’t think that is has ever worked.
In the internal Glyphs API (meaning objectiveC or plain c), doing someList[-1]
is not allowed. The path.nodes
allow it for closed paths that you can do nodes[idx - 1]
without checking if idx is greater than zero. So you can ask, give me the node previous to another (not give me the last on the list). I made the python version behave the same. So this is kind of on purpose.
I haven’t kept track of the script working with each update. The last time I used this script was in 2023. I am now on Glyphs 3311.
Fixed my script by replacing [-1]
with [len(path.nodes)-1]
, but I won’t lie it would be handy to have [-1] working
It’s fine for closed shapes. Only not working with open paths.
I ’ll see what I can do.
a side note: thisPath.selected
is rather slow. Avoid it in performance critical places. The fastest way to check for selection is node in layer.selection
. Or iterate over layer.selection
.