I have imported data from Matlab and want to use this to animate the rotations of two objects that I have already created in the scene. The loop I have created does not end up changing the object's rotational orientation on each keyframe; the animation is static and the objects do not move at all. If someone could point out an error in my code or my approach that would be greatly appreciated.

Thanks in advance.

import bpy

from math import *
from mathutils import *
import numpy as np

ob1 = bpy.data.objects['Retriever']
ob2 = bpy.data.objects['defectsatellite']
bpy.context.scene.objects.active = ob1
bpy.context.scene.objects.active = ob2

#Import the data from matlab "Equation Analysis" script        
rot1 = []
rot2 = []
x1 = np.loadtxt('C:\\Users\\Owner\\Desktop\\Math499\\Scripts\\defectsatelliterotation.csv')

for i in x1:

x2 = np.loadtxt('C:\\Users\\Owner\\Desktop\\Math499\\Scripts\\retrievalsatelliterotation.csv')

for i in x2:

#Set up key frames, controlling the rotation of each satellite.

#First extract every fifth row
def altelement(x):
   return x[::10]

rot1 = altelement(rot1)
rot2 = altelement(rot2)

sce = bpy.context.scene
frame_num = 0

for j in range(0,len(rot2)):

    ob1.rotation_euler.x = (rot1[j])
    ob2.rotation_euler.x = (rot2[j])
    ob1.keyframe_insert(data_path = "location", index = -1)
    ob2.keyframe_insert(data_path = "location", index = -1)
    frame_num += 1

1 Answer 1


You just need to change your keyframe statements:

ob1.keyframe_insert(data_path = "rotation_euler", index = -1)
ob2.keyframe_insert(data_path = "rotation_euler", index = -1)

You must log in to answer this question.

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