No method found for IsPointInside

Hi all,

I’m struggling with some code in python. I need to identify the layer of the object containing a point in space, based on multiple sources I found, I coded the following script (sorry I couldn’t attach a file).

 import rhinoscriptsyntax as rs
 import scriptcontext as sc
 import Rhino

 Breps = [sc.doc.Objects.Find(guid) for guid in rs.AllObjects() if rs.IsBrep(guid)]
 epsilon = sc.doc.ModelAbsoluteTolerance
 point3D = rs.CreatePoint(-45,45,45)
 for brep in Breps :
     solid=Rhino.Geometry.Brep()
     solid.Append(rs.coercebrep(brep))
     if solid.IsPointInside(point3D,epsilon,1):
         print(rs.ObjectLayer(brep))
         break

I’m running it inside rhino using the script editor, but then the following error shows up:

no method matches given arguments for Brep.IsPointInside: (<class ‘Rhino.Geometry.Point3d’>,<class ‘float’>,<class ‘int’>)

However, when I run it from the command ‘runpythonscript’ it works, so I don’t know what is going on or how to solve it. I guess it has something to do with the mess IronPython vs CPython (which to be honest I don’t get completely).

just to be clear, I’m trying to run it inside Rhino because there I can import NumPy, whereas outside it doesn’t import it (again due to the CPython thingy)…

anyway, I’d do appreciate if someone knows what is going on, or if I can somehow make the outside reader (a.k.a runpythonscript) to recognize NumPy.

thx

Hi @Ferney,

Maybe something like this?

#! python 3
import Rhino
import scriptcontext as sc

def TestFerney(point):
    object_type = Rhino.DocObjects.ObjectType.Brep
    objects = sc.doc.Objects.FindByObjectType(object_type)
    if not objects or 0 == len(objects):
        return

    tolerance = sc.doc.ModelAbsoluteTolerance
    strictly_in = True

    for obj in objects:
        brep = obj.Geometry
        if isinstance(brep, Rhino.Geometry.Brep):
            if not brep.IsSolid:
                continue
            if not brep.IsPointInside(point, tolerance, strictly_in):
                continue
            obj.Select(True)
            layer = sc.doc.Layers.FindIndex(obj.Attributes.LayerIndex)
            if layer:
                print(layer.Name)
    sc.doc.Views.Redraw()

if __name__ == "__main__":
    point = Rhino.Geometry.Point3d(5,5,5)
    TestFerney(point)

– Dale

Hi Dale, thank you thank you very much… it works perfectly!!

now for the sake of learning, I just wonder where lies the difference… the only ‘big’ change I see is the definition of the object to query for IsPointInside, while I define it as:

solid=Rhino.Geometry.Brep()
solid.Append(rs.coercebrep(brep))

whereas you define it as:

brep = obj.Geometry

I mean, AFAIU, I define the variable to take the ‘Brep’ geometry of the object only, while you send the ‘whole’ geometry

once again thank you very much

Hi Ferney,

You probably figured this out already, but the error message is because IsPointInside() is expecting a Boolean value as the third argument as a bool True instead of an int 1.