← Skills

ElixiFree Core (Generic CAD)

Native Read-only

ElixiFree core library API for generic CAD component generation

/skills/elixifree_core.md

Estimated tokens
1304
Characters
5216
Source
Native

Markdown

# ElixiFree Core Skill

Use the ElixiFree core library for all geometry. It provides clean, declarative
functions over FreeCAD's Part API. The library handles the FreeCAD details — you
supply dimensions and intent.

## Import

```python
from elixifree import (
    box, cylinder, sphere, cone, wedge, torus, prism, fuse, cut, intersect, translate, mirror, rotate, fillet, chamfer, bbox, center_of, place, select_edges, select_faces, Profile, rect_profile, circle_profile, polygon_profile, slot_profile, extrude, revolve, loft, sweep, shell, hole, cbore_hole, csk_hole, linear_array, polar_array, grid_array
)
```

## Standalone Mechanical Object Pattern

For generic single component projects, create one user-facing component and model
details as features:

```python
from elixifree import box, cylinder, cut, fillet

# Create base solids, subtract holes/sockets, add ribs/bosses, then add the result to the document.
```

Use raw FreeCAD only when the current ElixiFree API cannot express the required
geometry, and mark the script with `# ElixiFree gap: <reason>`.

## Ending every script

```python
from elixifree import add_to_doc
add_to_doc(result, "Body")
```

This handles document setup, recompute, and fitAll. Do NOT write these manually.

## Primitives

```
box(w, h, d, at=(0,0,0))                           -> Shape
cylinder(r, h, at=(0,0,0))                         -> Shape
sphere(r, at=(0,0,0))                               -> Shape
cone(r_base, r_top, h, at=(0,0,0))                 -> Shape
torus(r_major, r_minor, at=(0,0,0))                -> Shape
prism(points, h, at=(0,0,0))                       -> Shape   2D polygon extruded
wedge(dx, dy, dz, xmin, zmin, xmax, zmax, at)     -> Shape
```

## Booleans and transforms

```
cut(base, *tools)                     -> Shape   subtract tools from base
fuse(*shapes)                         -> Shape   join two or more shapes
intersect(a, b)                       -> Shape   common volume (raises if empty)
translate(shape, x=0, y=0, z=0)      -> Shape   move a copy
rotate(shape, axis, degrees, center)  -> Shape   rotate a copy; axis="X"|"Y"|"Z"
mirror(shape, plane="XZ")             -> Shape   mirror about "XY", "XZ", or "YZ"
```

## Edge/face operations

```
fillet(shape, radius, edges=None)     -> Shape   raises ValueError on failure
chamfer(shape, size, edges=None)      -> Shape   raises ValueError on failure
shell(shape, thickness, faces=None)   -> Shape   hollow out; opens faces= (default ">Z")
```

## Selectors (edges= and faces= arguments)

Use selector strings instead of geometry indices:
```
">Z"         top face / top edges
"<Z"         bottom face / bottom edges
">X", "<X"   outermost/innermost in X
">Y", "<Y"   outermost/innermost in Y
"|Z"         edges parallel to Z (vertical)
"#Z"         edges perpendicular to Z (horizontal)
"%CIRCLE"    circular edges
"%PLANE"     planar faces
"%CYLINDER"  cylindrical faces
">Z[0]"      topmost (Nth selector)
">Z AND %PLANE"  combinations with AND / OR
```

## Profile and solid-of-profile

```
profile(points, arcs=None)          -> Profile   closed 2D cross-section
rect_profile(w, h)                  -> Profile
circle_profile(r)                   -> Profile
polygon_profile(n, r)               -> Profile   regular n-gon, circumradius r
slot_profile(length, r)             -> Profile

extrude(p, length, plane="XY", at=None, symmetrical=False)  -> Shape
revolve(p, axis="Z", angle=360, at=None)                    -> Shape
loft([p1, p2, ...], ruled=False)                            -> Shape
sweep(p, path)                                              -> Shape
```

Position a profile: `p.at(x, y, z)` — returns a copy at world position.

## Holes

```
hole(shape, face, x, y, diameter, depth)                                    -> Shape
cbore_hole(shape, face, x, y, diameter, depth, cbore_diameter, cbore_depth) -> Shape
csk_hole(shape, face, x, y, diameter, depth, csk_diameter, csk_angle=82)    -> Shape
```

`face` is a selector string (e.g. `">Z"`). `depth` accepts a number or `"through"`.
`x`, `y` are offsets from the face centre in the face's local plane.

## Arrays

```
linear_array(shape, count, dx=0, dy=0, dz=0, fuse=True)         -> Shape or list
polar_array(shape, count, axis="Z", angle=360, center, fuse=True)-> Shape or list
grid_array(shape, nx, ny, dx, dy, fuse=True)                     -> Shape or list
```

## Placement helpers

```
bbox(shape)                              -> dict   xmin/xmax/ymin/ymax/zmin/zmax/xlen/ylen/zlen
center_of(shape)                         -> (cx, cy, cz)
place(shape, on, align="top", offset)    -> Shape
select_edges(shape, selector)            -> list[Edge]
select_faces(shape, selector)            -> list[Face]
```

`place` align values: "top", "bottom", "left", "right", "front", "back".

## Rules

1. **Always use ElixiFree functions.** Do not write raw `Part.makeBox`, `Part.makeCylinder` etc.
2. **Use `add_to_doc(result, "Body")` at the end** — never write doc/recompute/Gui lines.
3. **`fillet` and `chamfer` raise `ValueError` on failure** — do not call them with extreme radii.
4. If ElixiFree cannot express the geometry, use raw `Part` as a fallback and add a comment:
   `# ElixiFree gap: <description>`
v0.0.985