Python 'IndexOutOfRangeException' error on Rhino Geometry RayShoot

def rays_intersect(plane, rays, context):

    intPs = []

    for ray in rays:
        ray_from_plane = rg.Ray3d(plane.Origin, ray)
        intP = rg.Intersect.Intersection.RayShoot(ray_from_plane, context, 1)
        if intP == None:
            intPs.append(None)
        else:
            intPs.append(intP[0])
    return intPs

Hi,

I am trying to use the python script in Rhino 7 that I have made using Rhino 6 and seeing some issues as below.
’IntP’ suppose to append the point3d object to ‘intPs’ list and I believe that the item from array generated by RayShoot command needs to be called out with [0].

As this error is happening only in Rhino 7.
Any help would be greatly appreciated.

Thank you!
Sun

Hi @slee ,

i asume Rhino.Geometry.Intersect.Intersection.RayShoot method returns a list of Point3d, which can be empty if the ray misses. So instead of writing this:

if intP == None:
    intPs.append(None)
else:
    intPs.append(intP[0])

you might try to write it like this:

if intP.Count == 0:
    intPs.append(None)
else:
    intPs.append(intP[0])

It’s hard to test without a complete code example though.
_
c.

Thank you so much @clement. This is working well.

I have just checked that there was a difference between Rhino6 and Rhino7 regarding the return list.

When the return list is empty as you mention, Rhino 6 returns None

And for the same condition, Rhino 7 returns an empty list.