where I use a geometry nodes modifier to create a text object, convert it to mesh, and extract the vertices. As you can see, the vertices are showing in the spreadsheet.
But how do I access them from a python script?
The solution posted in the above thread doesn’t work in the case of Font objects as there’s this condition
if obj is None or obj.type != "MESH":
return
Thus I tried to remove it and changed @iceythe’s script to (it writes to console only for now)
import bpy
def print_verts():
obj = bpy.context.object
# Output geometry
obj_eval = obj.evaluated_get(bpy.context.view_layer.depsgraph)
# Write the header, pos x | pos y | pos z
print("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.
print(",".join(f"{c:.3f}" for c in v.co))
print_verts()
This throws the error:
AttributeError: 'TextCurve' object has no attribute 'vertices'
My understanding is that the above is script is not accessing the vertices created by geometry nodes, but the text object itself. Any thought?
If I convert the text to mesh I’m not able to modify the string in the future. The idea is to generate multiple strings programmatically and export the vertices
Indeed text objects are curves and don’t have meshes directly. However Blender still needs an intermediate, derived mesh to display them. We can get a copy of this mesh using obj.to_mesh().
I’ve updated the script to support both meshes and curves.
def print_verts():
obj = bpy.context.object
# Output geometry
obj_eval = obj.evaluated_get(bpy.context.view_layer.depsgraph)
# Write the header, pos x | pos y | pos z
print("pos x,pos y,pos z\n")
# Support curve types
mesh = obj_eval.to_mesh()
for v in mesh.vertices:
# ":.3f" means to use 3 fixed digits after the decimal point.
print(",".join(f"{c:.3f}" for c in v.co))
print_verts()