<p>You can use the openSCAD <code>projection()</code> function.</p>
<p>With <code>cut=true</code>, this slices your model at the Z=0 plane.</p>
<p><a href="https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#3D_to_2D_Projection" rel="nofollow noreferrer">3D to 2D Projection documentation</a>.</p>
<p><a href="https://i.sstatic.net/JN7hs.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JN7hs.png" alt="model to take cut from" /></a></p>
<pre><code>projection(cut = true) example002();
</code></pre>
<p><a href="https://i.sstatic.net/RXDjk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RXDjk.png" alt="projected cut" /></a></p>

CC BY-SA 4.0
2023-12-20T11:08:11.137Z
2023-12-20T15:13:19.440Z
2023-12-20T15:13:19.440Z
image_doctor
<p>Basically I am working on automating the generation of upper and lower shells of device enclosures. These enclosures have a rather irregular shape that was generated e.g. with <code>hull()</code>. I currently have a hollow enclosure object that I would like to split into an upper and a lower half in order to print them on a 3D printer. This is easily done by intersecting / diffing them with a large <code>cube</code> object. But I would like to also have a lid at the split position so both parts have a mechanically solid fit.</p>
<p>My approach would currently be to get the 2D surface of the cut plane and modify it to get an outer part for one shell and an inner part for the other shell. But I do not know how to get this surface object in the first step of the process.</p>
<p>Any ideas how to do this in OpenSCAD? Or even better proposals?</p>
<p>EDIT:</p>
<p>A possible workaround is as follows:</p>
<p>I model the inner hollow structure by combining the necessary room for the components. The enclosure is constructed by applying <code>minkowski() { inner(); sphere(r=wallThickness); }</code> to it. The overlapping lid parts are then generated by applying the Minkowski operation with a sphere half the wall thickness in size. Problem is, this creates a non-vertical overlap as you can see in the example by setting <code>cutHeight = 10</code> instead of <code>-20</code>. I know that having a vertical lid (i.e. perpendicular to the cut plane) may on the other hand lead to problems when the wall thickness is too thin.</p>
<pre><code>$fn=32;
wallThickness = 5;
lidHeight = 5;
cutHeight = -20;    // or 10

module inner()
{
    translate([0,0, cutHeight])
    hull() { // example only, may be an arbitrarily irregular shape
        translate([0, 0, 20]) sphere(40); 
        translate([20, 20, -10]) cube(50,center=true);
    }
}

module shell(wall)
{
    minkowski() {
        inner();
        sphere(wall);
    }
}

module lower_enclosure()
{
    union() {
        intersection() {
            difference() {
                shell(wallThickness);
                shell(0);
            }
            translate([0,0,-500]) cube(1000, center=true);
        }
        intersection() {
            difference() {
                shell(wallThickness/2);
                shell(0);
            }
            translate([0,0,-500 + lidHeight]) cube(1000, center=true);
        }
    }
}

module upper_enclosure()
{
    rotate([180,0,0]) 
    union() {
        intersection() {
            difference() {
                shell(wallThickness);
                shell(0);
            }
            translate([0,0,500]) cube(1000, center=true);
        }
        intersection() {
            difference() {
                shell(wallThickness);
                shell(wallThickness/2);
            }
            translate([0,0,500 - lidHeight]) cube(1000, center=true);
        }
    }
}


lower_enclosure();
translate([0,110,0]) upper_shell();
</code></pre>

CC BY-SA 4.0
2023-06-11T16:19:25.867Z
Any chance to make a sketch? Know that if you are creating lids, you need a rim so that it stays on top, the inner rim needs to be smaller than the hollow enclosure objects inside. It sound like you modelled the whole thing in OpenSCAD, so you can use that code for the lid? You can post your current code for reference.
0scar
CC BY-SA 4.0
2023-06-11T17:02:39.083Z
@0scar: I model the inner hollow structure by combining the necessary room for the components, say `hull() { translate([0, 0, 20]) sphere(40); translate([20, 20, -10]) cube(50,center=true); }` with the cut going through the XY plane. The enclosure is constructed by applying `minkowski() { inner(); sphere(r=wallThickness); }` to it. So, my current solution is now applying the Minkowski operation with a sphere half the wall thickness in size which generates the lid, and then combining this with cutting above and below the plane for the overlap. Problem is, this creates a non-vertical overlap.
Stefan
<openscad>
Get 2D object from a 3D object's face in OpenSCAD
Stefan
# Get 2D object from a 3D object's face in OpenSCAD

(Asked by: username_0 on 2023-06-11)

Basically I am working on automating the generation of upper and lower shells of device enclosures. These enclosures have a rather irregular shape that was generated e.g. with `hull()`. I currently have a hollow enclosure object that I would like to split into an upper and a lower half in order to print them on a 3D printer. This is easily done by intersecting / diffing them with a large `cube` object. But I would like to also have a lid at the split position so both parts have a mechanically solid fit.

My approach would currently be to get the 2D surface of the cut plane and modify it to get an outer part for one shell and an inner part for the other shell. But I do not know how to get this surface object in the first step of the process.

Any ideas how to do this in OpenSCAD? Or even better proposals?

EDIT:

A possible workaround is as follows:

I model the inner hollow structure by combining the necessary room for the components. The enclosure is constructed by applying `minkowski() { inner(); sphere(r=wallThickness); }` to it. The overlapping lid parts are then generated by applying the Minkowski operation with a sphere half the wall thickness in size. Problem is, this creates a non-vertical overlap as you can see in the example by setting `cutHeight = 10` instead of `-20`. I know that having a vertical lid (i.e. perpendicular to the cut plane) may on the other hand lead to problems when the wall thickness is too thin.

```
$fn=32;
wallThickness = 5;
lidHeight = 5;
cutHeight = -20;    // or 10

module inner()
{
    translate([0,0, cutHeight])
    hull() { // example only, may be an arbitrarily irregular shape
        translate([0, 0, 20]) sphere(40); 
        translate([20, 20, -10]) cube(50,center=true);
    }
}

module shell(wall)
{
    minkowski() {
        inner();
        sphere(wall);
    }
}

module lower_enclosure()
{
    union() {
        intersection() {
            difference() {
                shell(wallThickness);
                shell(0);
            }
            translate([0,0,-500]) cube(1000, center=true);
        }
        intersection() {
            difference() {
                shell(wallThickness/2);
                shell(0);
            }
            translate([0,0,-500 + lidHeight]) cube(1000, center=true);
        }
    }
}

module upper_enclosure()
{
    rotate([180,0,0]) 
    union() {
        intersection() {
            difference() {
                shell(wallThickness);
                shell(0);
            }
            translate([0,0,500]) cube(1000, center=true);
        }
        intersection() {
            difference() {
                shell(wallThickness);
                shell(wallThickness/2);
            }
            translate([0,0,500 - lidHeight]) cube(1000, center=true);
        }
    }
}

lower_enclosure();
translate([0,110,0]) upper_shell();

```

**Tags:** openscad

> **Comments:**
> **username_1**: Any chance to make a sketch? Know that if you are creating lids, you need a rim so that it stays on top, the inner rim needs to be smaller than the hollow enclosure objects inside. It sound like you modelled the whole thing in OpenSCAD, so you can use that code for the lid? You can post your current code for reference.  
> **username_0**: @username_1: I model the inner hollow structure by combining the necessary room for the components, say `hull() { translate([0, 0, 20]) sphere(40); translate([20, 20, -10]) cube(50,center=true); }` with the cut going through the XY plane. The enclosure is constructed by applying `minkowski() { inner(); sphere(r=wallThickness); }` to it. So, my current solution is now applying the Minkowski operation with a sphere half the wall thickness in size which generates the lid, and then combining this with cutting above and below the plane for the overlap. Problem is, this creates a non-vertical overlap.  

---

## 1 answers

### Answer by username_2 on 2023-12-20. Score: 1

You can use the openSCAD `projection()` function.

With `cut=true`, this slices your model at the Z=0 plane.

[3D to 2D Projection documentation](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#3D_to_2D_Projection).

[![model to take cut from](https://i.sstatic.net/JN7hs.png)](https://i.sstatic.net/JN7hs.png)

```
projection(cut = true) example002();

```

[![projected cut](https://i.sstatic.net/RXDjk.png)](https://i.sstatic.net/RXDjk.png)


---

