I am trying to make an animation creation script using cvs.

I referenced several csv scripts here, but I couldn't understand it at all because I not long ago learned Python.

How can I input the csv data of the attached photo to a specific object by creating a keyframe for each frame?

screenshot of spreadsheet with data

Here is a csv file with similar data


1 Answer 1


I'm assuming that you want to apply the animation to the current object. I'm also assuming that the csv file does not have the column headings but only the data. Finally, I'm assuming that the position and rotation are meant to be absolute values and not deltas.

That said, here's a script that does what you want:

import bpy
import csv

csvfilename = PATH_TO_YOUR_CSV_FILE

object = bpy.context.active_object
with open(csvfilename, newline='') as csvfile:
    csvreader = csv.reader(csvfile, delimiter=',')
    for row in csvreader:
        fn = int(row[0])
        loc = (float(row[1]), float(row[2]), float(row[3]))
        rot = (float(row[4]), float(row[5]), float(row[6]))
        print(fn, loc, rot)
        object.location = loc
        object.rotation_euler = rot
        object.keyframe_insert(data_path="location", frame=fn)
        object.keyframe_insert(data_path="rotation_euler", frame=fn)

This works by actually moving the object in world space and then adding keyframes for its location and rotation. There are several optimizations that could be applied to reduce the number of keyframes, and if you want deltas rather than absolute location and rotation you'll need to change the loc and rot creation; but it works as specified.

You can read about CSV handling in Python here and in more detail in PEP 305.

The blender manual entry for keyframe_insert might be helpful, although it's not terribly clear.


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