I’m struggling with adding nodes, especially off-curve (i.e. converting straight segment to curve). There seem to be multiple functions you can use for this purpose, but none of them seems to do the job. What’s the best way to do it, and if you have time, could you tell me what the differences are in the functions below?
What you want is the insertNode_atIndex_() function.
You create BCP1 and BCP2 and then you go:
myPath.insertNode_atIndex_(BCP1, 5)
myPath.insertNode_atIndex_(BCP2, 6)
5 and 6 being examples for the position in the path, 0 would be at the beginning, -1 at the end, etc.
divideCurve() will give you the coordinates of the two resulting segments if you add a node in the middle
addPoints() just sums up the coordinates
addNode_() and addNodeFast_() add a GSNode to the end of a GSPath
insertNodeWithPathTime_() inserts a node on the path, not changing the path’s shape.
Thanks both. I’ve finally managed to do it after two days of effort before I saw the responses. Looks like the way I found is correct (especially it took a lot of time to figure out that I had to change the type of one of the on-curves).
Because when you do a curve segment, you must specify an oncurve as last node. And when the curve segment is the last segment in your path, that node must be the same as the moveto you had specified at the beginning of the path (otherwise it would not be the last segment). In other words, the moveto at the beginning is superfluous.
I’m trying to build a rough filter myself, since there seems to be no way of accessing filters from Python.
The first step of Roughen filter places nodes by the distance specified in the field (with occasional skipping). How do you do that in Python? How can I place an on-curve node at, say, every 10 units on the curve? I can do it if I calculate the length of each segment and use insertNodeWithPathTime_(), which sounds very complicated, but do I have to do that?