r/openscad • • 6h ago

I built a small code-CAD language for AI assistants, here's a plant label script and the STL (ParaScript)

0 Upvotes

Disclosure: this is my own project.

I like OpenSCAD, but I wanted something an AI assistant could learn from a single file and write reliably. ParaScript is a small script language for 3D solids with a solver that runs in the browser and exports STL.

Here's the first test, a plant label (60x25 mm, 2 mm thick, 50 mm spike, 4 mm hanging hole). An assistant wrote it from the language guide; it compiled first time and the STL came out watertight (haven't printed it yet).

setup {
    name: "Plant Label",
    units: "mm",
    coordinate_system: "Z-up"
}

// Visible sizes are grouped by part. bite is a small overlap so unions stay closed.
parameters {
    tag: {
        width: 60.0,
        depth: 25.0,
        thickness: 2.0
    },
    spike: {
        width: 10.0,
        length: 35.0,
        bite: 1.0,
        tip: {
            width: 1.0,
            length: 15.0
        }
    },
    hole: {
        radius: 2.0,
        margin: 5.0
    }
}

// A flat taper from the shaft width down to a printable point, thickness unchanged.
// y = 0 is the point, y = tip length is the wide end. That end seats bite mm into the shaft.
// Faces follow the broom bristles: six walls of one closed solid.
def Tip = Component(
    solid: coords =>
        let length = $spike.tip.length in
        let thick = $tag.thickness in
        let wide = $spike.width in
        let narrow = $spike.tip.width in
        let half = u =>
            ((length - u) * (narrow / 2.0) / length) + (u * (wide / 2.0) / length) in
        let bottom = Surface2D(
            max_u: length,
            min_v: u => 0.0 - half(u: u),
            max_v: u => half(u: u),
            formula: u => v => Vector(coords: coords, x: v, y: u, z: 0.0)
        ) in
        let top_face = Surface2D(
            max_u: length,
            min_v: u => 0.0 - half(u: u),
            max_v: u => half(u: u),
            formula: u => v => Vector(coords: coords, x: v, y: u, z: thick)
        ) in
        let left = Surface2D(
            max_u: length,
            min_v: u => 0.0,
            max_v: u => thick,
            formula: u => v => Vector(coords: coords, x: 0.0 - half(u: u), y: u, z: v)
        ) in
        let right = Surface2D(
            max_u: length,
            min_v: u => 0.0,
            max_v: u => thick,
            formula: u => v => Vector(coords: coords, x: half(u: u), y: u, z: v)
        ) in
        let wide_end = Surface2D(
            max_u: wide,
            min_v: u => 0.0,
            max_v: u => thick,
            formula: u => v => Vector(
                coords: coords,
                x: u - (wide / 2.0),
                y: length,
                z: v
            )
        ) in
        let narrow_end = Surface2D(
            max_u: narrow,
            min_v: u => 0.0,
            max_v: u => thick,
            formula: u => v => Vector(
                coords: coords,
                x: u - (narrow / 2.0),
                y: 0.0,
                z: v
            )
        ) in
        Solid3D(faces: [bottom, top_face, left, right, wide_end, narrow_end]),
    expose: coords => {
        up: Vector(coords: coords, x: 0.0, y: 0.0, z: 1.0),
        right: Vector(coords: coords, x: 1.0, y: 0.0, z: 0.0),
        top: Vector(
            coords: coords,
            x: 0.0,
            y: $spike.tip.length,
            z: 0.0
        )
    }
)

def Shaft = Box(
    width: $spike.width,
    depth: $spike.length + (2.0 * $spike.bite),
    height: $tag.thickness
)

def Spike = Component(
    solid: join(
        frame: Shaft,
        placed: Tip,
        using: frame => placed => align(
            planar: meet(
                frame: frame.up,
                placed: placed.up
            ),
            translation: meet(
                frame: frame.corner.offset(
                    x: $spike.width / 2.0,
                    y: $spike.bite,
                    z: 0.0
                ),
                placed: placed.top
            ),
            rotation: meet(
                frame: frame.right,
                placed: placed.right
            )
        ),
        combine: frame => placed => frame + placed
    ),
    expose: coords => {
        up: Vector(coords: coords, x: 0.0, y: 0.0, z: 1.0),
        right: Vector(coords: coords, x: 1.0, y: 0.0, z: 0.0),
        top: Vector(
            coords: coords,
            x: $spike.width / 2.0,
            y: $spike.length + (2.0 * $spike.bite),
            z: 0.0
        )
    }
)

def Tag = Box(
    width: $tag.width,
    depth: $tag.depth,
    height: $tag.thickness
)

def TagWithSpike = Component(
    solid: join(
        frame: Tag,
        placed: Spike,
        using: frame => placed => align(
            planar: meet(
                frame: frame.up,
                placed: placed.up
            ),
            translation: meet(
                frame: frame.corner.offset(
                    x: $tag.width / 2.0,
                    y: $spike.bite,
                    z: 0.0
                ),
                placed: placed.top
            ),
            rotation: meet(
                frame: frame.right,
                placed: placed.right
            )
        ),
        combine: frame => placed => frame + placed
    ),
    expose: coords => {
        up: Vector(coords: coords, x: 0.0, y: 0.0, z: 1.0),
        right: Vector(coords: coords, x: 1.0, y: 0.0, z: 0.0),
        corner: Vector(coords: coords, x: 0.0, y: 0.0, z: 0.0)
    }
)

def PlantLabel = Component(
    solid: join(
        frame: TagWithSpike,
        placed: Cylinder(
            radius: $hole.radius,
            height: $tag.thickness
        ),
        using: frame => placed => align(
            planar: meet(
                frame: frame.up,
                placed: placed.up
            ),
            translation: meet(
                frame: frame.corner.offset(
                    x: $tag.width / 2.0,
                    y: $tag.depth - $hole.margin,
                    z: 0.0
                ),
                placed: placed.bottom
            ),
            rotation: meet(
                frame: frame.right,
                placed: placed.right
            )
        ),
        combine: frame => placed => frame - placed
    ),
    expose: coords => {
        origin: Vector(
            coords: coords,
            x: $tag.width / 2.0,
            y: $tag.depth / 2.0,
            z: 0.0
        )
    }
)

export(PlantLabel)

Differences from OpenSCAD that I'm unsure about, and would like opinions on: components are positioned by aligning exposed frames/points with join + align rather than nested translate/rotate transforms, and there are no text or taper primitives yet (so the tapered spike tip had to be built as a custom Solid3D from surfaces).

Try it (no sign-up): https://parascript.lindeque.family/ — there's a language guide and an llms.txt / AI assets file if you want to try it with your own assistant.

What would you want it to do that OpenSCAD makes awkward?


r/openscad • • 15h ago

Hackaday: Gardening With…OpenSCAD?

Thumbnail
hackaday.com
2 Upvotes

My wall-garden, designed in OpenSCAD, was promoted on the Hackaday blog!

OpenSCAD is where the innovation happens!

"To our knowledge, it’s the first time somebody sat down and wrote out all the code to generate a 3D model of a vertical garden in OpenSCAD." Tom Nardi

The project is open-source: https://github.com/wall-garden