# Assign Values of Control Point's Handle on a Curve using Python

I am interested in a script that could reassign the Z values of the control point handles in this curve to 0. Are these variables accessible to change via Python? Seems simple enough but my coding skillset is limited. Any help is appreciated.

https://i.imgur.com/hByRP3L.jpg

Following the link by batFINGER I attempted the following. My own simplistic coding knowledge is a limit here, unfortunately. Running the following does not produce errors but does nothing as well. If I move my last "for" statement outside of the "def", I get an "AssertionError" with line 17 and 45. (Note, I said 0 in original question but probably want "1" and "-1"? I just want the control point handles to align with the Z axis)

import bpy
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.

selected = bpy.context.selected_objects

def printInterpolatedCurveSegmentPoints(existingCurveObj):

spline = existingCurveObj.data.splines[0]
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
handle1.pointVec[2] = 1
handle2 = spline.bezier_points[nextIdx].handle_left
handle2.pointVec[2] = 1
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[0])
print("Point Y:", pointVec[1])
print("Point Z:", pointVec[2])
print()

for obj in selected:
printInterpolatedCurveSegmentPoints(obj)


Image of the problem. I have a mesh that I'm getting a set of outer vertices from. I have an Array and Curve modifier which allows my object to follow the curve. I want this wall to be vertical - not follow the Tilt of the inner arm of the Control Points - not sure the correct term. Maybe if I reassign the Face Normals before creating the Curve from the mesh, the points would align with the Z axis?

https://i.imgur.com/d0Y9SO7.jpg

This is image of the direction I would like the Tilt -

https://i.imgur.com/N0njvsN.jpg

• blender.stackexchange.com/questions/48924/… – batFINGER May 2 at 13:38
• Appreciate the link. I had experimented with that but mostly due to my own limited knowledge could not fully apply it. When I run my edits to that, nothing happens. I added a few lines to assign the pointVec on the 2 handles. I even tried without my edits. I'm sure a bit of it has to do with how I am trying to alter my selected object. – DP Roberts May 2 at 14:16
• It also seems that the above script will be handling the Bezier points and not the Control Points of the curve. Maybe "control vertices" is the correct term for the Tilt arms. I'm just trying to auto place an object with an array and curve and unfortunately, the object follows the Curve Tilt. – DP Roberts May 2 at 15:01
• – batFINGER May 2 at 15:09
• Could you please edit question to make images inline again. Think you have an XY Problem AFAIK the handles represent the tangent (or derivative) of the incoming spline segments to the point. Can't really set them orthogonal to the direction of curve. Possibly you are after the tilt. Select a control point in edit mode and N to see the setting. – batFINGER May 2 at 15:44