Boolean operation loop

Hi guys, I tried to make a loop to perform boolean union operation. The code is the following:


Two lists of brep are inputs. Search intersection first and then stored the intersected brep into a list for later union operation. The branch list will be updated after that. The code gave me this error: Solution exception: Error in IEnumeratorOfTWrapper.Current. Could not cast: Rhino.Geometry.Brep in Rhino.Geometry.Brep

I was wondering what this means, the union operation worked fine when I unified only two objects here. Thank you for your help.

If a Union fails or doesn’t fully work, it will return all parts.
This means CreateBooleanUnion returns a array of breps, not a single brep. So you need to put a [0] at the end to always take the first item (and maybe check if the array only has one item, in order to judge if the union was a full success).

Thank you! It worked when I put a [0] in front of the union. This command returns a list of brep.