# How do I divide a curve at t

I want to get a curve and split it at time=t.

I know about divideCurve() but I’m wondering if there’s already a function (`insertNodeWithPathTime_` maybe? ) to split a line instead of having to write the script that will delete and write a new one like here:

``````thisLayer = Glyphs.font.selectedLayers

pathList = []
for n in thisLayer.paths.nodes:
pathList += [(n.x, n.y)]
print n

newPathList = divideCurve(pathList,pathList,pathList,pathList,0.5)

print newPathList
thisLayer.paths = []

newPath = GSPath()

for i, p in enumerate(newPathList):
# 	print i, p
if i in [1,2,4,5]:
pPoint = GSNode(p, "offcurve")
elif i in [3,6]:
pPoint = GSNode(p, "curve")
pPoint.smooth = 1
elif type(p) != 'NSPoint':
pPoint = GSNode(p, "line")

``````

Perhaps here is something of use for you? But `insertNodeWithPathTime_()` sounds good to me too, if you seek exactly the functionality what is says.

Very basic sketch (works only on straight lines and no offcurve points (like a simple rect)), needs to be adapted for your needs:

``````thisLayer = Glyphs.font.selectedLayers
t = 0.5
oldPath = thisLayer.paths
newPath = oldPath.copy()
newPath.insertNodeWithPathTime_(t)
thisLayer.removePath_(oldPath)

Hey the insertNodeWithPathTime_ doesn’t work for me even on a straight line?

Does it not even work if you:

• draw a simple rect
• run the exact code snippet from above

?
Apparently for it to work, the path needs to be closed. I don’t know why. Might have to do with (not) indexing the path segments!?

What do you try to do? If you just like to divide an existing path, `insertNodeWithPathTime_` is all you need. The calculation of the proper path time value is a bit tricky. You need to use the index of the node that is at end of the segment in question and add the t value you need.

1 Like

got it thanks!