I’m writing a small script in python within grasshopper. I have two objects I want to boolean together, in some cases these to objects do no touch and I was expecting to get an error but I do not. I get returned the first element of the list.
So my question i:. Is it possible to return None/Error when the 2 objects are unable to join?
Rhinoscript syntax method rs.BooleanUnion() returns a list of guids with following elements: a guid of a newly created geometry made from union of initial two; or if those two initial geometries do not touch each other, it will return their original guids. This could be used to construct a conditional, to achieve a bit of what you want to do:
import rhinoscriptsyntax as rs
guids = rs.GetObjects("choose two geometry to union")
union = rs.BooleanUnion(guids)
print "Union successful"
return None # or "Error"
Actually, running objects through rs.BooleanUnion will return new GUIDS even if no union is found. @stevebaer This is IMO incorrect behavior, but that’s how it currently works. Worse, if the optional delete_input argument is set to False, new duplicate objects are returned and added to the file anyway… VB Rhinoscriptsyntax correctly returns Null (None) if the objects do not intersect.
OTOH, rs.BooleanUnion of two objects that don’t intersect in Python returns two objects (with different ID’s from their original ones), so if you’re only getting one, something else is going on…
If I use the Solid Union component from grasshopper I get the same result. I’ve attached a file, maybe it helps to narrow down the problem. I think it might be specific to the geometry, because I’ve tried the BU with another set of breps and it wont give me an error, but it will return a list with two elements.
Ok, so I am getting extremely confused. I think it might be a BUG. I’ve uploaded a second file with both internalized geometry from another GH file and the same geometry baked first and later internalized. I get 2 different results.
Internalized data from another GH file:
1.- if i do a solid union the result is the boolean intersection.
2.- if i do a solid intersection I get the boolean union.
Baked Geometry First and later interlnalized
1.- Get a solid union as expected
2.- Get a solid intersection as expected.
Normally, if you are getting unexpected (reversed) results from Boolean operations it is because one of the BReps you think is closed isn’t… and it’s got its normals facing inwards which will give inverse results from what you expect.
The fact that a solid union component on two disjoint BReps yields two BReps (the two originals) means it has the same behavior as the Python BooleanUnion method. That makes sense because both Python and GH are based on RhinoCommon and are calling the same code - namely
behind the scenes. This is supposed to return “An array of Brep results or null on failure.” The question is if the result of running a BooleanUnion on two disjoint BReps is to be considered a “failure” and return null or none… I seem to recall we have discussed this previously…