1
$\begingroup$

I working on a procedural system that defines two bezier curves and bevels them together. I cannot, for the life of me, figure out how to rotate the handles on the control vertices of my bezier curves.

import bpy
import mathutils

# do some rotation
bpy.ops.transform.transform(
    mode='ROTATION',
    value=0.6
)
# or
bpy.ops.transform.rotate(
    value=0.6
)
# or
p = bpy.context.active_object.splines[0].bezier_points[0]
p.handle_left = mathutils.Vector((1, 2, 3))


# nothing updates the viewport
bpy.ops.wm.redraw_timer(type='DRAW', iterations=1) # nope
# or
bpy.context.area.tag_redraw() # nope
# or
bpy.context.scene.update() # not a method
$\endgroup$
  • $\begingroup$ I've already tried bpy.ops.object.mode_set(mode='EDIT') for the ops function. Still doesn't update. $\endgroup$ – abraun Dec 2 '19 at 0:17
1
$\begingroup$

Rotating the handles of bezier curves.

enter image description here Running script in edit mode on default bez (blender 2.82)

There are some issues at play, eg what handle type you are using. I have set the type of both to 'FREE'

For example, here is a script to rotate both handles of point 0 of bezier curve by 45 degrees about the local z axis passing through the coordinate point.

Running the script 8 times should see the handles return to initial position.

To rotate have used one of the methods outlined in https://blender.stackexchange.com/a/7603/15543 which is probably a better way to go for a "Procedural System" than operators.

import bpy
from mathutils import Matrix
from math import radians

ob = bpy.context.object
cu = ob.data
spline = cu.splines[0]
p = spline.bezier_points[0]

M = (Matrix.Translation(p.co) @
     Matrix.Rotation(radians(45), 4, 'Z') @
     Matrix.Translation(-p.co))

p.handle_left_type = 'FREE' 
p.handle_right_type = 'FREE'  

p.handle_left = M @ p.handle_left
p.handle_right = M @ p.handle_right

Running the script in 2.81 in either mode produces the desired result and updates in the UI.

If you are having issues recommend that you look for errors in the system console, or IMO better still, test in the python console.

# this one throws a syntax error
bpy.ops.transform.transform(
    mode='ROTATION',
    value=0.6
)
# or this one relies on settings for axis an pivot point, but does rotate
bpy.ops.transform.rotate(
    value=0.6
)
|improve this answer|||||
$\endgroup$
  • $\begingroup$ Worked like a charm. Thanks! $\endgroup$ – abraun Dec 3 '19 at 20:47

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.