# BooleanDifference Operation

**URL:** <https://discourse.mcneel.com/t/booleandifference-operation/159707>\
**Category:** Grasshopper Developer\
**Tags:** windows, booleandifference\
**Created:** [May 11, 2023, 6:06am UTC](https://discourse.mcneel.com/t/booleandifference-operation/159707 "2023-05-11T06:06:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brent\_Burgess](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/brent_burgess/32/631732_2.png) [@Brent\_Burgess](https://discourse.mcneel.com/u/Brent_Burgess)\
**Post date:** [May 11, 2023, 6:06am UTC](https://discourse.mcneel.com/t/booleandifference-operation/159707/1 "2023-05-11T06:06:45Z")

</div>

Hi All,

I am having an issue with Boolean Differences

```auto
            beam = beam.CapPlanarHoles(0.01);
            beam = Brep.CreateBooleanDifference(beam, end1Box, 0.001)[0];

            DA.SetData(0, beam);

```

the beam is a solid, end1Box is a solid

I can return _beam_ and _end1Box_ individually from the code, however, when I run the CreateBooleanDifference it returns it as 1 big Brep.  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/2/7/3/2732d6a963afa4d74e1d4c9658fbace7dc481057.png)

If I take the 2 Breps individually and is the Solid difference node, it works as expected.  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/1/e/5/1e579901ba0bc335fd93481ef5788d25c3e3a51b.png)

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/d/a/ada0e1154fb2536b2f37ba5a49e77ac65eccce3e.png)

Have I misunderstood or missed something in the code?

---

<div class="post-metadata">

**Author:** ![Anil\_verma](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/anil_verma/32/476475_2.png) [@Anil\_verma](https://discourse.mcneel.com/u/Anil_verma)\
**Post date:** [May 11, 2023, 6:49am UTC](https://discourse.mcneel.com/t/booleandifference-operation/159707/2 "2023-05-11T06:49:33Z")

</div>

import Rhino.Geometry as rg

# create two spheres

sphere1 = rg.Sphere(rg.Point3d(0, 0, 0), 5)  
sphere2 = rg.Sphere(rg.Point3d(2, 0, 0), 5)

# create two breps from the spheres

brep1 = rg.Brep.CreateFromSphere(sphere1)  
brep2 = rg.Brep.CreateFromSphere(sphere2)

# perform boolean difference

result = rg.Brep.CreateBooleanDifference(brep1, [brep2], 0.001)

# output the result

a = result[0]

(It’s an ai generated code try something like this may be it will work, you can use "get geometry"instead of using create from sphere  
[ Something like this

import Rhino.Geometry as rg

# create two geometry inputs

geo1 = x[0]  
geo2 = x[1]

# create a Brep representation of the first geometry input

brep1 = rg.Brep.TryConvertBrep(geo1)

# create a Brep representation of the second geometry input

brep2 = rg.Brep.TryConvertBrep(geo2)

# perform a Boolean difference operation

result = rg.Brep.CreateBooleanDifference(brep1, brep2, 0.001)

# output the result

if result: # if the Boolean difference operation was successful  
output = result[0] # output the resulting geometry  
else:  
output = None # if the Boolean difference operation failed, output None  
]

---

<div class="post-metadata">

**Author:** ![Brent\_Burgess](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/brent_burgess/32/631732_2.png) [@Brent\_Burgess](https://discourse.mcneel.com/u/Brent_Burgess)\
**Post date:** [May 11, 2023, 7:28am UTC](https://discourse.mcneel.com/t/booleandifference-operation/159707/3 "2023-05-11T07:28:29Z")

</div>

Thanks for the reply. I completely forgot to mention that I am writing a custom node using C#. I don’t think it would make a difference, but thought I’d mention it

---

<div class="post-metadata">

**Author:** ![Brent\_Burgess](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/brent_burgess/32/631732_2.png) [@Brent\_Burgess](https://discourse.mcneel.com/u/Brent_Burgess)\
**Post date:** [May 11, 2023, 7:34am UTC](https://discourse.mcneel.com/t/booleandifference-operation/159707/4 "2023-05-11T07:34:11Z")

</div>

Found the solution. Beam had SolidOrientation as Inwards, and the box as outward. Once I flipped the beam, worked as expected

---

<div class="post-metadata">

**Author:** ![richard.aubin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/richard.aubin/32/502374_2.png) [@richard.aubin](https://discourse.mcneel.com/u/richard.aubin)\
**Post date:** [May 11, 2023, 7:58am UTC](https://discourse.mcneel.com/t/booleandifference-operation/159707/5 "2023-05-11T07:58:19Z")

</div>

Check surface normals. Usually boolean difference ending up as a union can be an inverted set of normals.
