I've read this post about grabbing the position of an object and exporting to a text file Exporting rotations of selected objects to a text file

I understand what it is doing but I'm looking to save the objects rotation values for the entire animation.

How do I get the rotation of an object over time? Not just keyframes, I'm looking to export a rotation value for every frame.


Using the example in the page you mentioned, it would be something like:

# import the necessary modules we need
# in our case, blender's python API and python's os module
import bpy, os
from math import degrees

# get the current selection
selection = bpy.context.selected_objects
scene = bpy.context.scene
startFrame = scene.frame_start
endFrame = scene.frame_end
currentFrame = scene.frame_current

# get path to render output (usually /tmp\)
tempFolder = os.path.abspath (bpy.context.scene.render.filepath)
# make a filename
filename = os.path.join (tempFolder, "newfile.txt")
# open a file to write to
file = open(filename, "w")

# iterate through the selected objects
for sel in selection:
    #cycle trough all the animated frames
    for i in range(endFrame-startFrame+1):
        #get true frame number
        frame = i + startFrame
        #set frame and get the object's rotation
        rot = sel.rotation_euler
        file.write("%s - frame %d - X:%f Y:%f Z:%f \n" % (sel.name, frame, degrees(rot.x), degrees(rot.y), degrees(rot.z)))

# close the file

#restore original frame (not necessary)

NOTE: there are more reliable ways to do it (like using fcurve data, etc...), but for simple uses this method is perfect.

NOTE 2: if you want to write this data to a .txt you probably want to read it too, so I would advise you to plan how to write your variables, based on the language you want to use to read it (if you need to read it in python I would write them with file.write("%s;%d;%f;%f;%f; \n" % (sel.name, frame, degrees(rot.x), degrees(rot.y), degrees(rot.z))) so that you can use the split(";") function). Also, it would be a good idea to write the object name only once before the first frame to save space

  • $\begingroup$ That's it! Perfect thank you. Not too fussed about the formatting, it's being streamed from Node over serial to an Arduino for servo control so is going to be transformed anyway. $\endgroup$
    – monkeytron
    Sep 6 '19 at 10:14
  • $\begingroup$ than please flag my answer as correct (the little tick under my answer's vote count), so that future readers know it worked $\endgroup$
    – Tareyes
    Sep 6 '19 at 12:53

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.