ReDo.Core runs any code that follows OpenSCAD support. These habits are what make a part easy to read, change and join to others.
Millimetres, Z up
One unit is one millimetre and Z points up. Add no conversion. A part stands on the floor at z = 0.
Capitals are fixed, lower case is a setting
A name in capitals, such as GRID or WALL, is a value nobody should change. A name in lower case, such as holes or length, is one the part is built around and a person may change. Since a part's code carries no comments, the case is how a reader tells the two apart.
WALL = 2;
length = 40;
cube([length, 10, WALL]);
Sit on the grid
ReDo's own parts are measured in grid cells of 10 mm: span(4) is four cells long, and hole_at(i) is the centre of cell i. A part sized in cells lines up with every other part on the grid. A size that has nothing to do with the grid, such as the length of a rod, stays in millimetres.
Chamfer first, then drill
chamfer() breaks every edge it reaches, so put it round the solid and cut the holes afterwards. The holes then keep sharp edges:
include <redo_constants.scad>
difference() {
chamfer(CHAMFER) cube([20, 20, 10]);
translate([10, 10, 0]) hole(SCREW_HOLE_D);
}
Use the library's CHAMFER (0.5 mm) rather than a size of your own. A chamfer must fit inside what it cuts: one as deep as a thin wall is refused.
Refuse what cannot be built
When two settings cannot go together, stop the build with assert() and a message saying what to change, rather than building something wrong:
holes = 3;
length = 40;
assert(holes * 10 <= length, "Make the part longer, or ask for fewer holes.");
cube([length, 10, 5]);
Give a choice as named options
When a part can be built in different ways, make it a word to choose and an if / else if on that word. Refuse any other word:
style = "round";
assert(style == "round" || style == "square", str("No style called ", style, "."));
if (style == "round") cylinder(h = 10, d = 10);
else if (style == "square") cube([10, 10, 10]);
Many holes, one pass
A plate with a field of holes gathers them in disjoint() and cuts them all in one go; see What ReDo.Core adds.
Declare what joins
Holes a screw goes in, pins and sockets are worth declaring, so the part joins others in the Playground; see Holes, pins and sockets.
No scaling
Parts are always full size. Do not scale() a finished part to make a bigger one; build it from its sizes instead.