How do I export a Font's vertex positions?

Hi, this is related to this other question, but possibly different.

I have this simple setup
A.blend (818.0 KB)

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?

Start with a Mesh object then add a geonode modifier to it instead of a text object?

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

You have stuck your geonodes modifier onto a curve object which means its being evaluated as a curve.

I stuck it on a cube which at least gets that print working, but as yet no evaluated verts!

Hope that get you closer…

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()
1 Like

Thanks, working here, one I realised I had not realised the instances!

1 Like

Thanks @iceythe and @AlphaChannel both are actually good suggestions (change the script or start from a mesh instead of a text object)!