I'm quite new in the blender and many things I do not understand yet. I would like to extract the coordinates of each vertex in CSV Well... I'm trying to use this script, but I can not make it work, supposedly copying / pasting it and pressing the "run" button should work, but there's no way.

Surely it is a very basic question, but the truth is, I have no idea.

I do not even know how to write the code correctly on this page :( (but I just found out ^^ )

import bpy

outputFile = 'C:/someFolder/mesh.csv'

verts = [ bpy.context.object.matrix_world * v.co for v in bpy.context.object.data.vertices ]

csvLines = [ ";".join([ str(v) for v in co ]) + "\n" for co in verts ]

f = open( outputFile, 'w' )
f.writelines( csvLines )

It always gives the same error in line #9 :

enter image description here

Thanks for reading this, any help will be very grateful. A greeting!

  • $\begingroup$ There seems to be nothing wrong with the script. I could run it just by pasting it in the text window. (It may have got something to do with the outputFile string.) To find the exact error run blender from console. On windows from start menu, click run then cmd. Go to blender dir 'cd <dir_name>' and execute blender. If you run the script now you should see the exact error message on the console. And keep coding, blender is such fun :) $\endgroup$ – Blender Dadaist Sep 11 '18 at 4:53
  • $\begingroup$ You can also toggle on the correct error console, see blender.stackexchange.com/questions/97976/… $\endgroup$ – Sazerac Sep 11 '18 at 4:54

Given that the error appears at opening the file, I strongly suspect that your outputFile is malformed:

Check that the path exists, the filename doesn't point to a directory, spaces in directory names are handled correctly etc.

You can paste the lines in the console one by one, the python interpreter will give you a verbose error message

Check these answers here

Where does console output go

Python script fail, look in the console for now


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.