MeshRay error in Python

Hi, I am running into an issue trying to execute the MeshRay function from Rhinocommon in Python. Specifically I am getting the error message 'float' object is not iterable on the following line of code:

intParm, intFace = Rhino.Geometry.Intersect.Intersection.MeshRay(someMesh, someRay)

I think the issue arises when trying to get the second output of the function, specifically the list of mesh faces that the ray intersects. However this works fine:

intParm = Rhino.Geometry.Intersect.Intersection.MeshRay(someMesh, someRay)

I can’t even think of an alternative way to call the function and still get the mesh face list, it is quite perplexing.

Hi Scott,

The second MeshRay method overload you are trying to call has an out parameter. Out parameters are not returned by method, but rather “filled” when supplied to the method call:

import System
import Rhino
import clr

# define someMesh, someRay

faceIndexArray = clr.StrongBox[System.Array[System.Int32]]()
t = Rhino.Geometry.Intersect.Intersection.MeshRay(someMesh, someRay, faceIndexArray)
if t >= 0:
    faceIndexL =  list(faceIndexArray.Value)
    print faceIndexL

Thanks! this worked great.

Where is this documented though? I found something very similar in an IronPython documentation for working with .NET libraries but it had a different Syntax that didn’t work in Rhino’s Python. I’m not sure where some of this syntax you are showing is coming from.

You can find more info on Check the explicit call on that page. clr.Reference is an equivalent to clr.StrongBox.
For typed arrays, check this page.