That's because you wrote a for-loop without braces, so it can only contain a single statement, and that single statement is your let().
Here is an equivalent way to write that section of code (and I did test it):
for (r = [ 1 : numRows ]) {
startColumn = ((c * thicknessWall) + ((c - 1) * batteryType));
startRow = ((r * thicknessWall) + ((r - 1) * batteryType));
translate([startColumn, startRow, thicknessWall])
cube([batteryType, batteryType, heightCompartment + 1]);
}
Side note, related to declaring variables but not an issue that you encountered: OpenSCAD does not allow setting the value of a variable more than once. So this code is illegal: x = 1;
echo(x);
x = 2;
echo(x);
Second note is that whenever you introduce a construct such as {union(), difference(), if(), for()}, variables declared within the braces are scoped, so they don't exist between iterations or after the scope ends. if (true) { y = -1; }
echo(y); // Illegal
However, just introducing braces without a construct does not restrict the variable to the scope: { z = 5; }
echo(z); // LegalAnd when something gets too trick, ChatGPT is amazing at writing in it. Often it nails the whole design in the first try, like https://bsky.app/profile/bradfitz.com/post/3maelwomyw22n to mask off certain Raspberry Pi pins to make reassembly of projects easier later.
$fn = $preview ? 32 : 64;The chatbots kept recommending I try using OpenSCAD but I resisted without even giving it a look. The results I had with just the Python script are quite adequate for the tasks I had. You can just ask the LLM to add a fillet to a vertical pin on a plane or to chamfer some edge and it is pretty good at doing it.
https://wiki.roshangeorge.dev/w/Blog/2025-12-01/Grounding_Yo... if you want to roughly see the workflow.
I'm going to try using OpenSCAD for things in the future. Does anyone else use exclusively an LLM with OpenSCAD (I used Claude Code and Codex) and if you do what did you do to make it more effective? The Python script wouldn't always generate printable meshes so I had to give it a check script to operate on.
If you don't need fancy features, have a look at FreeCAD as well.
I tried using Build123d, a Python library that lets you use all of the features of Python. And it's supposed to allow specifically things like box1.width, but it's always 0. Lots of other issues/bugs too, and severely lacking in ddocumentation.Maybe it'll get there some day.
Years later, I never actually got the hang of CadQuery, and I'm wondering if it was a mistake to write off OpenSCAD.
I am pretty new to CAD, so I don't actually know when I would run into OpenSCAD's limitations.
- functional programming model --- some folks find not having traditionally mutable variables limiting
- output is as an STL, or DXF using polylines
- native objects are spheres, cylinders, cubes, with functions for hull and Minkowski, so filleting and other traditional CAD operations can be difficult
I don't really see why that code is better, more logical, more readable or more robust than the equivalent quite trivial parametrics in more or less any GUI CAD program, and I think the geek discourse is really harmed by people who don't understand the value of the things that OpenSCAD can't ever offer.
This difference is profound, is the point I am getting at.
It also lacks any concept of constraints or constraint solving in 2D sketches, which makes some quite simple shapes extremely difficult to make without advanced maths.
So in both cases you never get away from the maths, and the maths complexity increases as your design complexity increases. You can see this reflected in the complexity of any large OpenSCAD codebase and in the number of functions in any large utility library.
CAD software should aid design. That’s its entire purpose. OpenSCAD just lets you plot 3D shapes and do some very limited operations to combine them.
My favorite thing I’ve printed is a little downsize coupler for the cool shirt system I built for my spec miata. It’s realllly silly & small thing, but it saved me!