Index through oncurve nodes while retaining original index number


I am trying to find a way to go through a list of nodes -> select only oncurve nodes --> index through oncurve nodes (however many there may be) while maintaining the index number from the original list.

I can make a list of the nodes and am able to manually select oncurve nodes by their index number. I’ve tried to automate this by matching the node.type == CURVE, however, this creates a new list with a different index.


list = []
for thisNode in thisPath.nodes:	
list = []

for thisNode in thisPath.nodes:
print thisNode

print 'LIST_OF_NODES:', list
print 'INDEX-2:', list[2]
print 'INDEX-5:', list[5]
print 'INDEX-8:', list[8]
print 'INDEX-11:', list[11]

matchesCurve = [thisNode for thisNode in lst if thisNode.type == CURVE]`
print 'LIST_MATCHES_CURVE_TYPE:', matchesCurve
print 'MATCHES_CURVE_TYPE INDEX-0:', matches[0]
print 'MATCHES_CURVE_TYPE INDEX-1:', matches[1]
print 'MATCHES_CURVE_TYPE INDEX-2:', matches[2]
print 'MATCHES_CURVE_TYPE INDEX-3:', matches[3]


LIST_OF_NODES: [<GSNode x=240.0 y=160.0 offcurve>, <GSNode x=280.0 y=201.0 offcurve>, <GSNode x=280.0 y=250.0 curve smooth>, <GSNode x=280.0 y=300.0 offcurve>, <GSNode x=255.0 y=360.0 offcurve>, <GSNode x=190.0 y=391.0 curve>, <GSNode x=134.0 y=355.0 offcurve>, <GSNode x=100.0 y=300.0 offcurve>, <GSNode x=100.0 y=250.0 curve smooth>, <GSNode x=100.0 y=201.0 offcurve>, <GSNode x=140.0 y=160.0 offcurve>, <GSNode x=190.0 y=160.0 curve smooth>]

INDEX-2: <GSNode x=280.0 y=250.0 curve smooth>
INDEX-5: <GSNode x=190.0 y=391.0 curve>
INDEX-8: <GSNode x=100.0 y=250.0 curve smooth>
INDEX-11: <GSNode x=190.0 y=160.0 curve smooth>

LIST_MATCHES_CURVE_TYPE: [<GSNode x=280.0 y=250.0 curve smooth>, <GSNode x=190.0 y=391.0 curve>, <GSNode x=100.0 y=250.0 curve smooth>, <GSNode x=190.0 y=160.0 curve smooth>]

MATCHES_CURVE_TYPE INDEX-0: <GSNode x=280.0 y=250.0 curve smooth>
MATCHES_CURVE_TYPE INDEX-1: <GSNode x=190.0 y=391.0 curve>
MATCHES_CURVE_TYPE INDEX-2: <GSNode x=100.0 y=250.0 curve smooth>
MATCHES_CURVE_TYPE INDEX-3: <GSNode x=190.0 y=160.0 curve smooth>

What are you are trying to do?
What you need the index for? You could store a tuple of the node and the original index.

I am trying to cycle through oncurve nodes while still being able to access the prev and next offcurve nodes.

  1. To what end?
  2. You mean the previous and next on-curve node? See the scripts I uploaded today in my repo. They select the following/previous oncurve. Perhaps you can take some inspiration from there.

I want to be able be able to jump through a list of nodes by selecting only the on-curve nodes (skipping over the off-curve nodes). Then when I reach specific on-curve node, I would like to be able to select the following/previous off-curve nodes (the handles) of that on-curve node.

I’ll have a look in your repo.

Why not just jump to the original list and just jump over the offcurve nodes.

And you can get to the index of a node by doing node.parent.nodes.index(node)