0
$\begingroup$

I'm trying to use python to export the x,y,z vertices to a file and then import that file back into blender to recreate the same image using just the x,y,z data points. I can convert the curves to a mesh but I'm having trouble exporting the vertices to a file. I get an error "'Curve' object has no attribute 'verts'" But the curve object seems to get converted into a mesh see images and code below.

import bpy

# Get the active mesh
obj = bpy.context.object.data

# Convert curve into mesh.
bpy.ops.object.convert(target='MESH')    


file = open('/tmp/obj_xyz.txt', 'w') # 'c:\\somefile.txt' for win32, 'w' if so we can write it.
for v in obj.verts:
    file.write('%.6f %.6f %.6f' % (v.co.x, v.co.y, v.co.z))
file.close()

Object as a curve Curve

Objects as a mesh Mesh

I'm trying to learn more about importing and export using python in Blender 2.8 so I'm trying to export the vertices of an object created using curves, then I will re-import the vertices from a file to see if the object will be the same.

I'm using Bender 2.8

I tried adapting some code I found online but it looks like things have changed link to code

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.