0
$\begingroup$

I have a python array:

x = [0,0.1, 0.5, .... ,45]

The number of elements in the array equals the number of frames in the scene.

Can I link or upload this array to an objects x-position?

I would love to avoid to loop through all frames and assign the position that way. I am new, therefore I am not sure what is best.

$\endgroup$
1
$\begingroup$

You can do it with something like that (the code is commented, so I think it is clear):

import bpy  
from mathutils import Vector

scene = bpy.context.scene

# Get the object
obj = bpy.context.object

# Define first frame and frame step
frame = 0  
frame_step = 10

# Your x positions array
x_positions = [0,0.1, 0.5, 0.7]


# Loop over positions
for x in x_positions:

    # Set the current frame
    scene.frame_set( frame )

    # Assign the location
    obj.location.x = x

    # Insert a key frame (replaces old one for this data path)
    obj.keyframe_insert( data_path = 'location' )

    # Go to next frame
    frame += frame_step
$\endgroup$

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.