# How to access coordinates of Bezier curve control point handles?

There are many examples of how to get the Control Points of a Bezier curve from Python. (For example, with a 2D bezier curve 'b'):

for ctrlPtIndex in range(0, numCtrlPts):
print("ptX:", b.data.splines.bezier_points[ctrlPtIndex].co)
print("ptY:", b.data.splines.bezier_points[ctrlPtIndex].co)


Is it possible to access the handle coordinates for each of these control points from bpy (python)?

I know that the handle-types can be changed for each control point in bpy, but can't find how to access the handle coordinates. These are plain curves created in Blender, they aren't connected to any armatures.

Thanks, Jon

Here is a Python function to print X, Y, Z values of the points given a curve object reference parameter.

import mathutils.geometry

# The parameters can be found by taking the coordinate and
# right handle of a point, and the coordinate and
# left handle of the next point in the Bezier points array.
# For cyclic curves the last point and the first point in the array
# form an extra segment.

def printInterpolatedCurveSegmentPoints(existingCurveObj):

spline = existingCurveObj.data.splines
numSegments = len(spline.bezier_points)
assert(numSegments >= 2)

r = spline.resolution_u
if spline.use_cyclic_u:
numSegments += 1

points = []
for i in range(numSegments):
nextIdx = (i + 1) % numSegments

knot1 = spline.bezier_points[i].co
handle1 = spline.bezier_points[i].handle_right
handle2 = spline.bezier_points[nextIdx].handle_left
knot2 = spline.bezier_points[nextIdx].co

_points = mathutils.geometry.interpolate_bezier(knot1, handle1, handle2, knot2, r)
points.extend(_points)

assert('3D' == existingCurveObj.data.dimensions)
for pointVec in points:
print("Point X:", pointVec)
print("Point Y:", pointVec)
print("Point Z:", pointVec)
print()