How to read all Texture Coordinates of a Mesh in RhinoCommon?

hi there,

I’m trying to read UVs (/texture coordinates) of a mesh, including discontinuous values, meaning those, that are different per face.
Here is a file with a simple mesh and discontinuous UVs:
disco_UVs.3dm (142.6 KB)
Mesh with UVEditor open:

Of course there is Mesh.TextureCoordinates, but that returns just one value per vertex.
For the sample file the following returns 9 for each of them.

import Rhino
doc = Rhino.RhinoDoc.ActiveDoc
for obj in doc.Objects:
    if isinstance(obj.Geometry, Rhino.Geometry.Mesh):
        mesh = obj.Geometry

I’m probably missing something, or don’t understand how Rhino stores these values.

I appreciate any help!

Hi @Bernd_Möller, they are stored in the mapping mesh which you can access like below:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    mesh_id = rs.GetObject("Mesh", 32, True, False)
    if not mesh_id: return
    mesh_obj = rs.coercerhinoobject(mesh_id, True, True)
    print mesh_obj.Geometry.TextureCoordinates.Count
    tm = mesh_obj.GetTextureMapping(1)
    rc, mapping_mesh = tm.TryGetMappingMesh()
    if rc: 
        print mapping_mesh.TextureCoordinates.Count


Great, thanks a lot @clement !
Looks like that returns the mesh, which is displayed when using the UVEditor. For the file above, it doesn’t look right, as it uses TopologyVertices, which are not aligned with the vertices on the 3D mesh.

Will need to dig deeper into this.