Powerful Design Process with OpenSCAD and LLMs

OpenSCAD is a CAD design platform that is fully script driven and allows highly accurate and parametrized 3D design. I started playing with OpenSCAD as an alternative to designing objects in FreeCAD or Fusion360.

OpenSCAD has a very difficult learning curve and requires knowledge, not only of spacial design principals, but the ability to descibe them as code. As someone who has never been terribly spacially gifted, I wanted hard parameters in my 3D designs but wanted to make the designs easy for me to visualize as I developed them.

Using ChatGPT or a similar LLM, I found that I could provide a prompt like “design a project box 6 inches by 12 inches with an opening on top in OpenSCAD” and it would emit code that provides a solid starting point for parametric design:

// Parameters
box_length = 12; // Length in inches
box_width = 6;   // Width in inches
box_height = 4;  // Height in inches (adjust as needed)
wall_thickness = 0.2; // Thickness of walls in inches
opening_length = 10;  // Length of the opening on top
opening_width = 4;    // Width of the opening on top

// Convert inches to millimeters (OpenSCAD works in mm)
inch_to_mm = 25.4;

// Dimensions in mm
box_length_mm = box_length * inch_to_mm;
box_width_mm = box_width * inch_to_mm;
box_height_mm = box_height * inch_to_mm;
wall_thickness_mm = wall_thickness * inch_to_mm;
opening_length_mm = opening_length * inch_to_mm;
opening_width_mm = opening_width * inch_to_mm;

module project_box() {
    difference() {
        // Outer box
        cube([box_length_mm, box_width_mm, box_height_mm], center = false);

        // Inner hollow space
        translate([wall_thickness_mm, wall_thickness_mm, wall_thickness_mm])
            cube([box_length_mm - 2 * wall_thickness_mm,
                  box_width_mm - 2 * wall_thickness_mm,
                  box_height_mm],
                 center = false);

        // Top opening
        translate([(box_length_mm - opening_length_mm) / 2,
                    (box_width_mm - opening_width_mm) / 2,
                    box_height_mm - wall_thickness_mm])
            cube([opening_length_mm, opening_width_mm, wall_thickness_mm * 2], center = false);
    }
}

// Render the project box
project_box();

There’s always issues with such code, and adding additional objects like a lid can prove difficult for an LLM to correctly add to a design, but getting the groundwork is a huge plus.