How do I get from the index of a mesh point to its 3D point in Rhinocommon? Or just how to iterate over every face in a mesh, doing something looking at the vertices of each?
I was messing around at first trying to do this through rs.MeshFaces at first but wasn’t quite getting what I expected so I figured I should try to ‘do it right’ with RhinoCommon but I’m a bit lost about meshes.
Quickie sample - the mesh vertex list has a method Point3dAt(index)
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def GetMeshVertex3DPoint(vertices,index):
return vertices.Point3dAt(index)
mesh_id=rs.GetObject("Select mesh",32,preselect=True)
if mesh_id:
mesh=rs.coercemesh(mesh_id)
verts=mesh.Vertices
max_index=verts.Count-1
index=rs.GetInteger("Index to find?",minimum=0,maximum=max_index)
if index is not None:
pt=GetMeshVertex3DPoint(verts,index)
if pt: rs.AddPoint(pt)