path.pointAtPathTime_ issue

It looks to me that in order to get through a path’s segments, i need to add 2 to the 0.x time. Sometimes counting from 2 in whole steps actually brings me to the correct segments. e.g. path.pointAtPathTime_(2.5) is the half of my first segment when it has handles. when it doesn’t have handles, its middle is at t = 0.5

Is there a way to determine pointAtPathTime with the same fractional value between 0 and 1 on every path segment, no matter if it is a line [ len(segment) == 2 ] or a curve?

Currently I am trying add 2 to the fractional value plus the index of the segment. But I get strange results. I kinda don’t see what’s happening here.

The integer part of the pathtime is the index of the node at the end of the segment.

So to recap:

If the first segment is a line, the node at the end of this segment has the index (and therefore the integer part) 0.
If the first segment is a line, the second segment is a curve, the node at the end of the second segment has the index (and therefore the integer part) 3 and third segment has the 4. And so on.

I think I understand how it works now and can make function to properly iterate over the segments. Thank you.

This is what I came up with:

t = 0.25
for path in layer.paths:
    nodeCOunter = -1
    for segment in path.segments:
        if len(segment) == 2: # is a line
	    nodeCOunter += 1
	if len(segment) == 4: # is a curve
	    nodeCOunter += 3
        # or instead the last 4 lines: `nodeCOunter += len(segment) - 1`
	division = path.pointAtPathTime_(nodeCOunter + t)

Don’t iterate the segments! The data model is build around the node list. The segments have to be generated (and then they are never used).

Iterate the nodes.

t = 0.25
for path in layer.paths:
	nodeCOunter = 0
	for node in path.nodes:
		if node.type != OFFCURVE:
			division = path.pointAtPathTime_(nodeCOunter + t)
		nodeCOunter += 1

Oh thanks for the info. Wasn’t aware of this. Just seen segments being used in other code and started off with them.

Are they too intense on calculating power? I still want to use the segment.length attribute. May I still do this?

What do you need the segment.length for? Just check node.type if its CURVE or LINE.

The whole thing I am working on is more complex than the snippet I posted here. I need the length for an apparent equal division of the segments. The longer it is, the more divisions I want. What is the problem with using segments?

Mostly performance. And you loose some settings (smooth connection, corners, user data) of the nodes.

Where do you get the segment.length from?

I don’t need the node types here. The segment.length is from iterating over the segments. I got it in it’s help(), along with .start & .end