I have 2 meshes and I can manually perform a boolean difference on the 2 in the GUI, which yields the desired result. Now I like to perform that exact same operation on the very same data in a Python script:
def BooleanDifference():
filter = Rhino.DocObjects.ObjectType.AnyObject
rc, mesh1 = Rhino.Input.RhinoGet.GetOneObject("Select mesh to subtract from", False, filter)
if rc != Rhino.Commands.Result.Success: return rc
if not mesh1: return Rhino.Commands.Result.Failure
rc, mesh2 = Rhino.Input.RhinoGet.GetOneObject("Select mesh to subtract", False, filter)
if rc != Rhino.Commands.Result.Success: return rc
if not mesh2: return Rhino.Commands.Result.Failure
tolerance = scriptcontext.doc.ModelAbsoluteTolerance
rc, dub = Rhino.Geometry.Mesh.CreateBooleanDifference(mesh1, mesh2, tolerance)
if rc != Rhino.Commands.Result.Success: return rc
if not dub: return Rhino.Commands.Result.Failure
scriptcontext.doc.Views.Redraw()
return Rhino.Commands.Result.Success
The function CreateBooleanDifference
refuses to execute, presumably because I fail to capture or type-cast the mesh object reference correctly into IEnumerables before I hand them into the difference function.
The error message is:
TypeError: Rhino.DocObjects.ObjRef value cannot be converted to System.Collections.Generic.IEnumerable`1[Rhino.Geometry.Mesh] in method Rhino.Geometry.Mesh[] CreateBooleanDifference(System.Collections.Generic.IEnumerable`1[Rhino.Geometry.Mesh], System.Collections.Generic.IEnumerable`1[Rhino.Geometry.Mesh], Rhino.Geometry.MeshBooleanOptions, Rhino.Commands.Result ByRef)
So how would I do that?