Is there a function that will return all objects that intersect a plane, for example the XY Plane? I want the guid of any polysurface that shares an intersection with the plane.
Preferably in Python but will take anything at this point. Rhino API or Rhinoscript.
I can find quite a lot that will return back points and lines but require choosing the object first. I want the reverse. I want to find the objects that intersect the plane.
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def SelObjsIntersectPlane(objIDs,plane,tol):
breps=[rs.coercebrep(objID) for objID in objIDs]
yes_intersect=[]
for i,brep in enumerate(breps):
if brep:
insec=Rhino.Geometry.Intersect.Intersection.BrepPlane(brep,plane,tol)
if insec and insec[0]: yes_intersect.append(objIDs[i])
return yes_intersect
def TestFunction():
tol=sc.doc.ModelAbsoluteTolerance
plane=Rhino.Geometry.Plane.WorldXY
objIDs=rs.ObjectsByType(16,state=1)
if objIDs:
to_select=SelObjsIntersectPlane(objIDs,plane,tol)
rs.SelectObjects(to_select)
TestFunction()
I could use a little help with this. I modified it to allow selection of surfaces. I am attaching a simple Rhino file with six surfaces that form an exploded box. The vertical surfaces intersect the XY Plane. When you run the code it leaves the top one unselected but selects the bottom for some reason. I just want to select the sides. Only items that intersect the plane. Can you help with this?
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def SelObjsIntersectPlane(objIDs,plane,tol):
breps=[rs.coercebrep(objID) for objID in objIDs]
yes_intersect=[]
for i,brep in enumerate(breps):
if brep:
insec=Rhino.Geometry.Intersect.Intersection.BrepPlane(brep,plane,tol)
if insec and insec[0]: yes_intersect.append(objIDs[i])
return yes_intersect
def TestFunction():
tol=sc.doc.ModelAbsoluteTolerance
plane=Rhino.Geometry.Plane.WorldXY
objIDs=rs.ObjectsByType(8|16|1073741824,state=1)
if objIDs:
to_select=SelObjsIntersectPlane(objIDs,plane,tol)
rs.SelectObjects(to_select)
TestFunction()
OK, that’s strange, it’s reporting that there is an intersection (insec[0] returns as True) even though there is none. So, I modified the script to check if there were any curves or points that actually resulted from the intersection:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def SelObjsIntersectPlane(objIDs,plane,tol):
breps=[rs.coercebrep(objID) for objID in objIDs]
yes_intersect=[]
for i,brep in enumerate(breps):
if brep:
insec=Rhino.Geometry.Intersect.Intersection.BrepPlane(brep,plane,tol)
if insec and insec[0]:
if insec[1] or insec[2]:
yes_intersect.append(objIDs[i])
return yes_intersect
def TestFunction():
tol=sc.doc.ModelAbsoluteTolerance
plane=Rhino.Geometry.Plane.WorldXY
objIDs=rs.ObjectsByType(8+16+1073741824,state=1)
if objIDs:
to_select=SelObjsIntersectPlane(objIDs,plane,tol)
rs.SelectObjects(to_select)
TestFunction()
Let me know if that works… late here, I’ll check tomorrow.