I am very new to blender and I am trying to move a cube in an environment. I have a csv file with a list of coordinates designated by columns, each column is the X, Y, or Z coordinates with n rows. From this list, I am trying to read the file in blender and move the cube to the coordinates in each row. Any python coding help or tips would be fantastic.

New contributor
Jot1925 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • $\begingroup$ there are only 3 columns (x, y, z) and you need to iterate over each row? $\endgroup$ – Virgil Sisoe Feb 11 at 20:27

Assuming you need only the first 3 columns of each row and you need to iterate over, one way of doing could be this. you need to have your object selected

Example csv:
1.1, 1.3, 1.1
2.2, 2,1, 2.3
import bpy
import csv

csv_path = "path_to_your_csv"

with open(csv_path) as file:
    csv = csv.reader(file, delimiter=",")
    # iterate over each rows assuming you need only
    # the the first 3 columns (if there are more)
    for row in csv:
        # row is a list with strings elements so must be converted in float
        x, y, z, *_ = [float(value) for value in row]
        bpy.ops.transform.translate(value=(x, y, z))
  • $\begingroup$ Thank you for the help Virgil! I tried your code and I am still having problems with reading the csv file. I need to find a way to change the values from strings to floats so they can be used in blender. $\endgroup$ – Jot1925 Feb 12 at 14:27
  • $\begingroup$ if you use my code then this line does just that. x, y, z, *_ = [float(value) for value in row]. if you are instead using part of this code into your, you could show it so I can help you better $\endgroup$ – Virgil Sisoe Feb 12 at 16:48

Your Answer

Jot1925 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.