World location of Bezier Points

Greetings,

I’m working on a script to export bezier curves into a csv file. The issue I’m having is the the bezier_points are in local space instead of world space. All the examples I’ve run across for converting to world space involve getting the matrix_world of the object. It does not appear that curves extend off of object and therefore do not have this matrix. So how would one go about transforming bezier_points into world space?

with open(basedir+"/test.csv",'w',newline='') as file:

    writer = csv.writer(file,delimiter = ',') 
    count = 0
    writer.writerow(["","x","y","z",
            "i_x","i_y","i_z",
            "o_x","o_y","o_z"])
    for obj in bpy.data.curves:

        for curve in obj.splines:
            
            for bezpoint in curve.bezier_points:
                
                count += 1
                writer.writerow([count, bezpoint.co.x,bezpoint.co.y, bezpoint.co.z,
                    bezpoint.handle_left.x,bezpoint.handle_left.y,bezpoint.handle_left.z,
                    bezpoint.handle_right.x,bezpoint.handle_right.y,bezpoint.handle_right.z])

Hi and welcome,
You need to add few lines :

with open(basedir+"/test.csv",'w',newline='') as file:

    writer = csv.writer(file,delimiter = ',') 
    count = 0
    writer.writerow(["","x","y","z",
            "i_x","i_y","i_z",
            "o_x","o_y","o_z"])
    for obj in bpy.data.curves:
        ob_curve = bpy.data.objects.get(obj.name, None)
        for curve in obj.splines:
            
            for bezpoint in curve.bezier_points:
                xyz = ob_curve.matrix_world @ bezpoint.co
                xyz_left = ob_curve.matrix_world @ bezpoint.handle_left
                xyz_right = ob_curve.matrix_world @ bezpoint.handle_right
                count += 1
                writer.writerow([count, xyz[0], xyz[1], xyz[2],
                xyz_left[0], xyz_left[1], xyz_left[2],
                xyz_right[0], xyz_right[1], xyz_right[2]])
1 Like

Ah! Much appreciated.