# Generating STL file from KiCad

Making a projectbox with all the holes in the right place is quite a challenge.

Luckily for the makers that use **`KiCad`** as a PCB making tool there is a rescue!

### Tools needed

If not already done you first have to install the latest version of [FreeCAD](https://www.freecad.org/).\
Then you have to install the **`KiCadStepUp`** tool with the **`Addon Manager`**.

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FULqzmqgm7r7Qo7qc6y1P%2FFreeCAD_Addon-Manager.png?alt=media&#x26;token=3cccabe5-b8e9-4847-92d0-01d814bb2dfd" alt=""><figcaption></figcaption></figure>

### Creating a STEP file with KiCad

Start the **`PCB Editor`**

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FDCIswiyleg66j2n2EtX5%2FKiCad_Select-PCB-Editor.png?alt=media&#x26;token=41c61509-7964-4a9f-bf2b-d30b31e4788a" alt=""><figcaption></figcaption></figure>

From the **`File`** menu select **`Export -> STEP`**

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FIkvhLKKYbEl2LqOS4Bcd%2FKiCad_Select-Export-STEP.png?alt=media&#x26;token=906b4b6f-5b05-4747-8bd0-754057de04ce" alt=""><figcaption></figcaption></figure>

In the popUp **`[Browse]`** to the map where you want to save the STEP file and click on **`[Export]`**.

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FfN8EaqxXPr8GKjVaPaMG%2FKiCad_popUp-Export.png?alt=media&#x26;token=ed680afa-a962-4f78-ae4a-77038a08f574" alt=""><figcaption></figcaption></figure>

### Start FreeCAD

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FTGjKY4sBk8qdxkjKBOVK%2FFreeCAD_Splash.png?alt=media&#x26;token=aa12a017-a073-472c-a41b-491b1df943b9" alt=""><figcaption></figcaption></figure>

Click on the select box ..

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FRJ6PWgVaVQ5gdOLNF2Kc%2FFreeCAD_Select_Setup.png?alt=media&#x26;token=821e79fb-4b9e-4f02-a22c-08dbc174b3ba" alt=""><figcaption></figcaption></figure>

.. and select the **`KiCadStepUp`** tool

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FYnysPHb4XC0mUSfwWXPK%2FKiCad_SelectStepUp-tool.png?alt=media&#x26;token=12aedd13-07d6-4707-ac6f-594cac941258" alt=""><figcaption></figcaption></figure>

Go to **`File->Open`** and select the STEP file from the KiCad Export

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FOGSDosiYKOgMCrFWKgeO%2FKiCad_Open-STEP-file.png?alt=media&#x26;token=029b2ee3-a91e-43a4-a042-4993e038dd0b" alt=""><figcaption></figcaption></figure>

.. and click on **`[Open]`**

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2F84NdzG0U59nseOoM5DSn%2FKiCad_Select-STEP-file.png?alt=media&#x26;token=cd7ed667-14a0-4e36-b7cf-265dbc86ddd4" alt=""><figcaption></figcaption></figure>

After a while you see the result of this import

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2F9sMrUUYtQ6PXWTmnb3uD%2FKiCad_Window2.png?alt=media&#x26;token=e56b75de-82c3-4cd4-96fd-9e67c4ff69d8" alt=""><figcaption></figcaption></figure>

Now all you have to do is **`Export`** this file

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FJRVd6nNNBsOwoP6bLGwp%2FKiCad_Export_Active.png?alt=media&#x26;token=7a237364-961d-42d2-9c5a-ceeacce32f3f" alt=""><figcaption></figcaption></figure>

Select "**`STL Mesh`**" as type ..

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FCN9RT22v6hMqPleVFCXv%2FKiCad_Export-As-STL.png?alt=media&#x26;token=8e3bffba-cbf7-4ac9-9912-299b49633217" alt=""><figcaption></figcaption></figure>

.. and click on **`[Save]`**

The result is a nice STL file

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FjAITwiGRdfh0I13eUK9k%2FKiCad_Show_Resulting-STL.png?alt=media&#x26;token=9d806cf8-7030-4d5e-b269-171a58fedd22" alt=""><figcaption></figcaption></figure>

## Use this STL file with the YAPPgenerator

Add the following code to the beginning of your **`.scad`** file:

```
myPcb = "./STL/DSMRloggerESP32_PCB.stl";

if (true)
{
  translate([42,43,4.6]) 
  {
    rotate([0,0,90]) color("darkgray") import(myPcb);
  }
}
```

**`myPcb`** has to point to the generated **`.stl`** file\
With **`translate()`** and **`rotate()`** you can place the **`.stl`** file to the exact location of your projectbox. This is a bit fiddling in the beginning but once set it does not change anymore.

<figure><img src="https://832938294-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcI46RW7gXIHinmkl2pBq%2Fuploads%2FMtkGmk5NGBsDpbkmQfTF%2FYAPP_PCB_fiddling.png?alt=media&#x26;token=7bf602a5-00b1-41f7-ae29-7e45a9f3869d" alt=""><figcaption></figcaption></figure>
