← All ideas
  • Published 14 Nov 2018

Python API: Getting a spline's length, U value for a bezier point.

I needed to calculate a curve's length for a Python script the other day, and found that the most common way people do this is by converting the curve to a mesh and measuring each edge, or doing the bezier math directly.

This forum post has discussion and code snippets of the current work-arounds: blenderartists.org/t/length-of-a-bezier-curve-in-2-5/496672/13

Why add something to the Python API when there are other ways to do it? Two reasons: first, because several operators in Blender (such as Follow Path Constraint) use the length of a curve as a parameter. Second, because Blender already seems to be doing this for constraints-- try sliding the offset parameter on curve constraints, path animation, etc. I think this addition would be particularly useful for rigging scripts, since it would make it much easier to make rigs that don't jiggle when switching between edit mode and pose mode.

I propose the following additions to the Python API:

spline_length(endPoint=1, startPoint=0) This function would accept two u values along the curve and calculate the distance between them in Blender Units. It would default to measuring between the first and last point (0 and 1), but the user could specify any segment of the curve with the u value parameters.

spline_uValue(controlPoint ) This fucntion would report the u value of a control point in the curve, either Bezier or NURBS.

spline_uValue_location(uValue = 0) This function woul report the coordinates of the specific u value of the curve.

Of course I welcome any improvements to my suggestion -- I'm still new to Blender's Python API and I'm not a Blender developer.

100%

Development Status: Open

Upvote 5 Downvote 0
Josephbburg
14 Nov 2018

0 Comments