Box with two holes

Hello,

I just started working with Grasshopper and c#. My question may seem very simple to you.

I want to drill two holes in a box. I managed to draw the box and the cylinders. I’ve been trying to subtract the cylinders from the box geometry but failed.

So far I tried CreateBooleanDifference method, and failed.

Thanks for help!

unnamed.gh (3.6 KB)

Hello,

I changed the B output to cylinder1, and then applied Solid Difference, this is working.

Are you attempting to do the solid difference in C# ?

Hello magicteddy,

Thanks for your answer. Yes, I’m trying to it with c#.

Your intervals were flipped, this caused normal orientation problems.

private void RunScript(double x, double y, double z, ref object A, ref object B, ref object C, ref object D)
  {
    //Algorithm
    Interval X = new Interval(0, x);
    Interval Y = new Interval(0, y);
    Interval Z = new Interval(0, z);

    Box box = new Box(Plane.WorldXY, X, Y, Z);

    Brep boxBrep = box.ToBrep();

    Point3d point1 = new Point3d(0, 0, z);
    Point3d point2 = new Point3d(x, 0, z);
    Point3d point3 = new Point3d(0, y, z);

    Plane plane = new Plane(point1, point2, point3);

    Point3d center1 = new Point3d(x / 2, y / 4, z);
    Point3d center2 = new Point3d(x / 2, 3 * y / 4, z);

    Circle circle1 = new Circle(plane, center1, x / 4);
    Circle circle2 = new Circle(plane, center2, x / 4);

    Cylinder cylinder1 = new Cylinder(circle1, -z);
    Cylinder cylinder2 = new Cylinder(circle2, -z);

    Brep[] sd = Brep.CreateBooleanDifference(new List<Brep>(){boxBrep}, new List<Brep>(){cylinder1.ToBrep(true, true),cylinder2.ToBrep(true, true)}, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

    //Output
    A = box;
    B = cylinder1;
    C = cylinder2;
    D = sd;
  }
1 Like