Python Update: How to Animate Text in Blender

WhereIsMyMind

I’m generally opposed to functions that overload on parameters. But seeing as how Blender functions do it all the time, I figured I’d go nuts for this updated text animation function.

So What’s New?

The first time around, I added if clauses to account for the different sizes of the letters because I am 36 times an idiot (yes, I’m six hours into a Poirot binge). Blender has object dimensions that you can call as variables. That’ll tell you how far over you need to move each character to make the letters readable. That’s this guy by the way:

bpy.context.object.dimensions.x

Adding that shortened my first version considerably.

Onto the parameters! I want to be able to set the start location, end location, start frame, end frame of the first object, frame increment, start rotation, and end rotation. Since locations and rotations all have three values for the x, y, and z axis, this is ever so slightly busy. But cool because you can customize the hell out of it.

Here’s the breakdown.

Code ExplainedChange up the parameters to get different effects. Rotation, sliding about, or some combination of the two.

Once Upon A Time

The Code

import bpy

#tx = start x, ty = start y, tz=start z
#ex = offset x, ey = offset y, ez = offset z
#sf = start frame of all letters
#ef = first letter stop frame
#inc = frame increment
def movetext(string, tx, ty, tz, ex, ey, ez, sf, ef, inc, sxr, syr, szr, exr, eyr, ezr):
sl = list(string)
x=0
while x < len(sl):
bpy.ops.object.text_add(location=(tx,ty,tz), rotation=(sxr,syr,szr))
ob=bpy.context.object
ob.data.body = sl[x]
bpy.context.scene.update()
ob.keyframe_insert(data_path="location",frame=sf)
ob.keyframe_insert(data_path="rotation_euler", frame=sf)
ob.location.x = ex + tx
ob.location.y = ey + ty
ob.location.z = ez + tz
ob.rotation_euler=[exr, eyr, ezr]
ob.keyframe_insert(data_path="location",frame=ef)
ob.keyframe_insert(data_path="rotation_euler", frame=ef)
ef += inc
x+=1
tx = tx + bpy.context.object.dimensions.x

movetext("Eat-Sleep-Rave-Repeat", 1, 10, 0, 2, -10, 0, 0, 2, 8, 0, 0, 0, 1.57, 0, 0)

 

Advertisements

5 thoughts on “Python Update: How to Animate Text in Blender

    1. Not weird at all! That tripped me up too–Blender has two places you can execute scripts. One is the Python Console (if you want to enter in scripts line by line), and the other is the Text Editor (that’s my preference for larger blocks of Python).

      There are screenshots in this old post of how to get to the Text Editor:
      https://gifguide2code.wordpress.com/2016/10/01/python-how-to-cipher-in-blender/

      Or you can just hit Shift + F11.

      Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s