I looked over here and found a csv reading script that creates curves, wich is exactly what I need, it´s cool, but I need to modify it because I need to read a differently formated csv, in fact I need to create different lists with different values, my CSV looks like this:

uniquename, x, y, z, diameter, name 401_JJ, 2800, 15500, 21400, 406, 401_JJ a, 2800, 15500, 24150, 406, 401_JJ

The thing is that I need to extract a names list, a unique names list, a diameter list and a coordinates list.

I know that with this code I extract the first 3 rows and convert them to a vector collection, but I don´t know how to modify this and extract specific positions, for example, 2,3,4 as vectors, 1 as string, 5 as float and 6 as string.

Hope someone can help me out here.



1 Answer 1


Use the excellent csv module built into Python for that. The Python documentation has plenty of examples on how to read and write CSV files.

Once you have a row, you can convert individual bits to other objects, like so:

vec = mathutils.Vector([float(coord) for coord in row[1:4]])

The explicit conversion to float is necessary as CSV is untyped, so every field is returned as string.

The [f(x) for x in collection] construct is called a list comprehension, and is also explained in the Python documentation.

  • $\begingroup$ So in this case, using "row[1:3]" is telling Blender that the Vector coord should be created with the data existent in row 1, 2 and 3? For example, if I want to pick rows 2,3 and 4 I should use "row[2:4]", correct? Thanks for the docs link, I´m going to check it right away. $\endgroup$
    – Juangea
    Nov 23, 2017 at 18:42
  • $\begingroup$ I made a mistake, it should be [1:4]: from index 1 up to but not including index 4. $\endgroup$
    – dr. Sybren
    Nov 24, 2017 at 8:02

You must log in to answer this question.

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