1
$\begingroup$

in advance.

I'm writing a script to change Z, for every control point in a bezier, so the final curve will have the same initial shape, but will follow a 'descending' path, from start to end.

Steps can be either constant or heights can be read from a list/array.

With the following code, I've been unable to get bpy.ops.curve.select_nth(), inside a loop, giving me the result I was expecting (as in each control point being selected, individually, in order to be translated)...

    import bpy

    segs = 5
    height = 10
    step = height / (segs + 1)

    bpy.ops.curve.select_all()
    bpy.ops.curve.subdivide(number_cuts=(segs - 1))
    bpy.ops.curve.select_all()

    for i in range(segs):
        bpy.ops.curve.select_nth(nth=2)
        bpy.ops.transform.translate(value=(0.0, 0.0, (step * i)))

Even outside the loop, it seems bpy.ops.curve.select_nth() does not work (or I'm missing something).

Any suggestion?

$\endgroup$
1
$\begingroup$

After some more research and tests, I got the results I wanted with

import bpy

segs = 7
alt = 1
step = alt / (segs + 1)

bpy.ops.curve.select_all()
bpy.ops.curve.subdivide(number_cuts=(segs - 1))
curve = bpy.context.object
bez_points = curve.data.splines[0].bezier_points

i = 0
for bez_point in bez_points:
    bez_points[i].co.z = (i * step)
    bez_points[i].handle_left.z = (i * step) - (step / 2)
    bez_points[i].handle_right.z = (i * step) + (step / 2)
    i += 1

for bez_point in bez_points:
    bez_point.handle_left_type = 'AUTO'
    bez_point.handle_right_type = 'AUTO'
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.