How do I Export an Object's Vertex Positions?

I’m not too familiar with the CSV format, but if it’s literally just a comma between each row and a newline for each column, you could have something like this.

import bpy
import os


def write_verts():
    obj = bpy.context.object

    if obj is None or obj.type != "MESH":
        return

    # Output geometry
    obj_eval = obj.evaluated_get(bpy.context.view_layer.depsgraph)
    filepath = "vertices.csv"
    
    with open(filepath, "w") as file:
        # Write the header, pos x | pos y | pos z
        file.write("pos x,pos y,pos z\n")

        for v in obj_eval.data.vertices:
            # ":.3f" means to use 3 fixed digits after the decimal point.
            file.write(f",".join(f"{c:.3f}" for c in v.co) + "\n")

    print(f"File was written to {os.path.join(os.getcwd(), filepath)}")

if __name__ == "__main__":
    write_verts()

Based on your blend file, this produces a vertices.csv file with this format:

pos x,pos y,pos z
0.762,-1.298,3.000
0.000,-1.500,3.000
1.298,-0.762,3.000
-1.298,-0.762,3.000
-1.500,0.000,3.000
-0.762,-1.298,3.000
1.016,-1.730,1.000
0.979,-1.666,1.630
0.000,-1.926,1.630
0.000,-2.000,1.000
0.885,-1.506,2.304
0.000,-1.741,2.304
2 Likes