0
$\begingroup$

I have used the script to move an object using CSV. Can it be modified to include rotation as well? Can this be done using one imported file, or is it best with two imported files. One for Location the other for Rotation.

The object needs to move and rotate using all csv coordinates.

import bpy
import csv

f = start_frame = 1
frames_per_row = 10    
csv_path = "C:/Book3.csv"

ob = bpy.context.object

with open(csv_path) as file:
    csv = csv.reader(file, delimiter=",")

    for row in csv:
        ob.location = [float(v) for v in row[:3]]
        ob.keyframe_insert("location", frame=f)
        f += frames_per_row
$\endgroup$
2
$\begingroup$

This is a somewhat trivial task given the code is basically already there

Data contained in the same csv with columns like:

loc_x,loc_y,loc_z,rot_x,rot_y,rot_z

import bpy
import csv


f = start_frame = 1
frames_per_row = 10    
csv_path = "C:/Book3.csv"

ob = bpy.context.object

with open(csv_path) as file:
    csv = csv.reader(file, delimiter=",")

    for row in csv:
        ob.location = [float(v) for v in row[:3]]
        ob.rotation_euler = [float(v) for v in row[3:6]]
        ob.keyframe_insert("location", frame=f)
        ob.keyframe_insert("rotation_euler", frame=f)
        f += frames_per_row

If two files need to be used you can either zip them beforehand or keep track using the keyframe. It is also possible to use quaternion rotation.

| improve this answer | |
$\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.