Unable to perform SolidDifference in GHPython Scripting

I have problem while doing Boolean difference of two solids in Python scripting component.

  1. If I use difference = rs.BooleanDifference(Box, Spheres) then the error is “Runtime error(NullReferenceException): Object reference not set to an instance of an object”.

  2. If I use difference = Rhino.Geometry.Brep.CreateBooleanDifference(Box, Spheres, 0.01) then the error is “Runtime error(ArgumentTypeException): expected Brep, got Guid”.

But if I take the output of Box and Spheres and input them to a different Python scripting component and perform the 1st method then it works fine. Also using SolidDifference component

Random Pores in 3D 1.gh (7.3 KB) works fine.

Please help me with this.

Thank you !

use method two
right click on input parameters and set type hint to Brep
https://apidocs.co/apps/rhinocommon/6.14.19118/M_Rhino_Geometry_Brep_CreateBooleanDifference_1.htm here is the API doc of the method. The method arguments are IEnumerable<> so wrap your single box in a list like [Box]

Hi Will_Wang,

Thanks for the reply. Yeah selecting type hint as Brep on input parametres it works only if I come out of the Python scripting component and I have to create another component.
I want to perform Boolean operation in the Python scripting component itself.

I also tried your idea of wrapping Box in a list, but I got error as unexpected indent .

Can you please edit the Python component in my Grasshopper file and help me ?

Thank You!

difference = Rhino.Geometry.Brep.CreateBooleanDifference(
    [rs.coercebrep(s) for s in Spheres],

add this to end of your code


Hi Will_Wang,

Thank you very very much for your help. Now my Boolean Difference is working fine.

I have one more query. If the Spheres created are completely inside and isolated in the Box then the Boolean Difference won’t happen. The Boolean Difference occurs only if the spheres are intersecting the Box.


Please check out this link https://www.reddit.com/r/rhino/comments/36lbm4/how_come_i_can_only_use_boolean_difference_when/

Please forgive me if this is a naive question. Is there any way to remove isolated Spheres (without any intersection with boundary of Box) from the Box.

Thank You!

Hi - if by “remove” you mean subtract and not just delete, you could take a look at the NonmanifoldMerge command.

But please do note the “If you don’t want to do anything in Rhino with the result” part of that post.

1 Like