Mesh face centroids Grasshopper VB.Net

Hi All,
how can I access the coordinates of Mesh Face centroids in Grasshopper Scripting?
I only found the Mesh.FaceNormals.ComputeFaceNormals method, but it returns a boolean - which doesn’t help me that much.

Basically, I’m looking for an equivalent rhino.MeshFaceCenters(strMesh) method from rhinoscript for Grasshopper scripting.

Thanks a lot for any help!
Chris

Hi @Christoph1,

for a single mesh face you can use:

mesh.Faces.GetFaceCenter(index) 

where index is the number of the mesh face. To get all centers in one go, you could use something like this:

import Rhino
import rhinoscriptsyntax as rs

def MeshFaceCenters():
    id = rs.GetObject("select mesh", 32, True, False)
    if not id: return
    
    mesh = rs.coercemesh(id)
    centers = [mesh.Faces.GetFaceCenter(i) for i in xrange(mesh.Faces.Count)]
    
    rs.AddPoints(centers)
    
if __name__=="__main__":
    MeshFaceCenters()

Here is more info about GetFaceCenters() method.

c.

1 Like

Thanks! That helped!

…and mesh.FaceNormals.item(index) gives me the normals.

I just realized, that the auto-completion in the script-components of Grasshopper is not complete. So, e.g. it didn’t show me the .item list. So I should rather look up class functions here: http://4.rhino3d.com/5/rhinocommon/

Cheers Chris