Hi Everyone,
I hope this is the right place to be posting.
Since discovering what python can do in Blender helping me with my work, I’ve been hooked.
I have a .csv file (see attached). What I want to achieve is to add a cube at each of those locations. So the 1st column would be the x co-ordinate. The top row would be the y co-ordinate and then the corresponding value in the table would be the z co-ordinate.
So as per the .csv the 1st cube would be added at (1, 0, 19.445) and then the 2nd cube at (1, 1, 19.485) and so on and then move on to the next row where the x value would be 2.
I honestly couldn’t figure it out because I had to skip the 1st row where the ‘y’ values are located. For all the .csv files I’ll be using the y value will increase by 1 every time in any case so I tried to make that happen with a while loop.
I went scouring the internet and stealing other peoples code but I couldn’t piece together something that could work. I got it to a point where the 1st column could get done but I couldn’t get it to move on to the next column.
So whether it builds by going column to column or row to row doesn’t matter.
Here is my last laughable attempt that has the 1st column but added 29 times over itself, but now in a triangle!
import bpy, csv
path = "C:\CSVImport\C-Scan_CAP_Useme.txt" # this is where I stored the .csv on my PC
with open(path) as csvfile:
content = csv.reader(csvfile, delimiter='\t', dialect='excel') # the .csv is seperated by tabs
for i,row in enumerate(content):
if i == 0: continue # As far as I understand this skips the 1st line
a = 1
x = row [0]
y = x
z = row [a]
while i > 0: #I used a while loop. So while there are still rows the script should keep adding cubes?
#'float' makes the text an integer I think...
bpy.ops.mesh.primitive_cube_add(location = (float(x), float(y) ,float(z)))
a = a + 1
y = float(y) + 1
i -= 1
If you could take the time to review my problem I’d be forever grateful.
C-Scan_CAP_Useme.txt (37.0 KB)