Even distribution between nodes along a path

Hi there. I’ve been trying to create a script which segments curved paths and then straightens them out. I know a similar effect is achievable through the roughen filter at 0 displacement, but I need to be able to determine AMOUNT of segments, rather than just the distance between segments.

for thisPath in Layer.paths:	
	# step backwards through nodes so we do not mess up point indexes:
	for thisNode in thisPath.nodes[::-1]:
		if thisNode.type != OFFCURVE:
			# on-curve index + 0.5 is the center of the segment:
				segmentCorners = 4
				for i in range(1, segmentCorners + 1):
					#pathTime = thisNode.index+(1 / segmentCorners)
					pathTime = thisNode.index+(1/segmentCorners * i)
					thisPath.insertNodeWithPathTime_(pathTime)
			

	for thisNode in thisPath.nodes[::-1]:
		if thisNode.type != OFFCURVE:
			thisNode.type = LINE

This is what I have so far, with segmentCorners being how much segments I wish to create. Below is the result, see how the points between the O vary?

Any help would be really appreciated!

Figured it out!

segmentCorners = 4
				for i in range(1, segmentCorners + 1):
					output = 1 / (segmentCorners + 1 - i)
					pathTime = thisNode.index+(output)
					thisPath.insertNodeWithPathTime_(pathTime)

There is a few mekkablue scripts and a plug-in for even distribution. You can steal code form there.