1
$\begingroup$

I am trying to find the right code to animate text that follows a bezier curve in python blender api. I can add the keyframes, and they appear to be working when I drag through the timeline, but when I run script it sets just one keyframe. I need to be able to tell it the start keyframe at frame 1 and the end keyframe at frame 249. Here is part of the code I am using:

bpy.context.object.name = "Text"

bpy.ops.object.modifier_add(type='CURVE')
bpy.context.object.modifiers["Curve"].object = bpy.data.objects["Circle.Text"]

bpy.context.object.modifiers["Curve"].deform_axis = 'NEG_X'

bpy.ops.transform.rotate(value=1.5708, axis=(1, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)


bpy.ops.transform.translate(value=(12.8872, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=True)

bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success=False, always_prompt=False)


bpy.ops.transform.translate(value=(-11.6886, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=True)
bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success=False, always_prompt=False)

Thanks in advance if anyone can help.

$\endgroup$

1 Answer 1

1
$\begingroup$

Ditch the operators

enter image description here Test run with default text and default bezier circle objects

Below is code which does, what I believe to be, same as above, but without any operators. For case of example I have used an object named "Text" in scene for text object, and an object named "BezierCircle" for the curve. Change to suit

import bpy
from mathutils import Matrix, Vector
from math import radians

context = bpy.context
scene = context.scene

text = scene.objects.get("Text")
curve = scene.objects.get("BezierCircle")

if text and curve:
    # add modifier
    cm = text.modifiers.new("foo", 'CURVE')
    cm.object = curve
    cm.deform_axis = 'NEG_X'
    # rotate 
    R = Matrix.Rotation(radians(90), 4, 'X')
    text.matrix_world @= R # replace @ with * for pre 2.8
    # translation
    text.matrix_world.translation += Vector((12.8872, 0, 0))
    # insert keyframe
    text.keyframe_insert("location", frame=1)
    # and again
    text.matrix_world.translation += Vector((-11.6886, 0, 0))
    text.keyframe_insert("location", frame=249)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .