# pycodecad

Code-CAD with [build123d](https://github.com/gumyr/build123d): write a Python script, see the part,
export it for 3D printing.

A desktop window shows the files of a part, its code and parameters next to the 3D view, and runs
the script only when you press Run. The same script runs from the command line, so an AI assistant
can check its own work with `check` and `render`.

![The pycodecad window: the files of the folder, parameters and code on the left, a gear in the 3D view on the right](https://offerrall.github.io/pycodecad/images/window.png)

```python
from build123d import Box, Cylinder
from pycodecad import show

plate = Box(40, 30, 8) - Cylinder(5, 8)
show(plate, name="plate", color="#F4B02A")
```

A part is one plain Python script that builds shapes with build123d and passes them to `show()`.
pycodecad opens a window on it, runs it in a fresh child process, and exports what it shows. The
window, the command line and an AI assistant all look at the same scene, so what an assistant checks
is what you see and what you print.

## What you get

- **A window** on a part: its files, the code and the part side by side. It runs the part once when
  it opens, then only when you press Run, and writes only when you press Save. Errors point at the
  line, and the last good part stays on screen. See [The window](https://offerrall.github.io/doc/pycodecad/window.md).
- **Parameters**: `expose(fn)` turns the arguments of a function into sliders, number boxes and
  checkboxes. See [Parameters](https://offerrall.github.io/doc/pycodecad/parameters.md).
- **Animations**: `frame()` saves the scene as a frame; the window plays them. Parts built once and
  moved with `Pos` are not computed again, so mechanisms play in real time. See
  [Scripts](https://offerrall.github.io/doc/pycodecad/scripts.md#frame).
- **A command line**: `check`, `render` and `export` run the same script without a window, and
  `pycodecad examples` copies the bundled examples to a folder and opens them. See
  [Command line](https://offerrall.github.io/doc/pycodecad/cli.md).
- **An AI workflow**: an assistant edits the file and checks its own work with `check` and
  `render`, which draws the part from several views in one picture. See
  [Working with an AI assistant](https://offerrall.github.io/doc/pycodecad/ai.md).
- **Exports** to STL, 3MF (also a profile for Bambu Studio), STEP, GLB and BREP, from the window or
  the command line.
- **Parts for your own app** (experimental): the window's code, parameters and 3D view as Dear
  ImGui components, in `pycodecad.embed`. See [Embedding pycodecad in your app](https://offerrall.github.io/doc/pycodecad/embedding.md).

pycodecad is small on purpose: thin glue over well-tested libraries, readable in an afternoon. See
[Design](https://offerrall.github.io/doc/pycodecad/design.md#small-on-purpose).

## Requirements

A graphics card with OpenGL 3.3. Linux is the native, tested platform; Windows and macOS are
compatible targets, with the differences listed in [Limitations](https://offerrall.github.io/doc/pycodecad/limitations.md).

## Credits

- [build123d](https://github.com/gumyr/build123d): the modeling language
- [Open CASCADE](https://dev.opencascade.org/) and [OCP](https://github.com/CadQuery/OCP): the geometry kernel
- [Dear ImGui](https://github.com/ocornut/imgui) and [slimgui](https://github.com/nurpax/slimgui): the interface
- [ModernGL](https://github.com/moderngl/moderngl), [GLFW](https://www.glfw.org/) and
  [pyGLFW](https://github.com/FlorianRhiem/pyGLFW): rendering and windows
- [NumPy](https://numpy.org/): meshes
- [pytypehint](https://offerrall.github.io/pytypehint/): the parameters of `expose()`
- [Lucide](https://lucide.dev): icons (ISC)
