Accessing data in the UV layout in Python? I learned how to export the UV layout from here,


but am still unclear how to access the data in Python.

By "access the data," I mean getting an array that tells me where each vertex ends up in the UV map (in other words, UV and vertex ID for each of the vertex above). This is why exporting the UV layout as a rasterized .png, as above, is not acceptable.

The hacky way in my mind...

I can imagine exporting the UV layout to a vector image (.svg and .eps supported by the above-referenced addon), and then extracting the coordinates from the vector image, but this sounds like a hack that requires parsing .svg or .eps. I believe since we can export it, there must be a way for us to directly access the data.

What I tried

I've fiddled with tessface_uv_textures, uv_layers, uv_textures, but they are all either empty lists or None, probably because my material is just a diffuse shader of a color. But this should have nothing to do with the UV layout though, right?
Turns out I need to get into the EDIT mode and select all vertices, and then perform the projection.

bpy.ops.object.mode_set(mode='OBJECT')
bpy.context.scene.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.smart_project()
bpy.ops.object.mode_set(mode='OBJECT')


After that, accessing data is as easy as the solution given in Get/Set coordinates for UV vertices using Python.