Lets3dPrint scripts
A project's timeline written as plain lines you can read, change and run. Every step of the timeline is one line (a sketch is a short block). Change a number and press Run: the part rebuilds. Or write a script from scratch, with variables and loops.
# A plate with a row of pegs
w = 80 # Width (40 to 200)
d = 50 # Depth (20 to 120)
pegs = 5 # Pegs (1 to 12)
base = sketch on xy
rect (-w/2, -d/2) to (w/2, d/2)
end
plate = extrude base by 5 as "Plate"
repeat i from 1 to pegs
cylinder r 3 h 10 on xy offset 5 at (-w/2 + i * w / (pegs + 1), 0) join into plate
end
fillet plate edges 1, 3 r 2
Values and script files
The numbers set at the top of a script (outside sketches and loops) appear above it as Values: a field for each, and a slider when its comment ends with a range. The comment is its label. Change one and the part rebuilds.
cables = 6 # Cables (1 to 12)
cable = 5 # Cable diameter (2 to 12)
gap = 4 # Wall between cables
The comment lines at the very top describe the script. Save Script… in the script panel writes it as a .l3dscript file (plain text). File → Run Script File… (⇧⌘R, also in Create and ⌘K) opens one in any project: set its values, then add its steps to the end of the timeline, or let it replace the project. A script added to a project can use the project's steps and bodies by the names the script view gives them (plate, "Base plate").
Basics
- One command per line.
#starts a comment. - Numbers are millimetres and degrees. Write sums freely:
w/2 + 3,sqrt(2) * 10. - Functions:
sin cos tan(degrees),sqrt abs min max round floor ceil, andpi. name = 12sets a variable;name = <command>gives a step a name to refer to later.- Points are
(x, y); 3D points and vectors are(x, y, z). repeat i from 1 to 10 [step 2]…endrepeats lines;if a > b…else…endchooses.- Comparisons
< <= > >= == !=, combined withand,or,not.trueis 1,falseis 0. - Texts in quotes:
label = "BOX"; texts compare with==and!=. A value likelid = "snap" # Lid (none, snap, screw)shows as a menu,rounded = trueas a switch. define peg(x, y)…endnames some lines;peg(10, 5)runs them with x and y set.
Any step can end with named "Its name" (its name in the timeline), as "Body name" (the body it creates) and suppressed.
Planes, faces, edges, operations
- Planes:
xy,xz,yz, optionallyoffset 5; or a flat face of a body:face 3 of plate. - Bodies: a step's name (
plate) or a body's name in quotes ("Bracket"). - How a new solid combines:
new,join,cut,intersect, optionallyinto plate. - Faces and edges are numbered as the inspector shows them (from 1).
- Or name them by where they are, so the script works for any values:
face top of box(alsobottom,front,back,left,right;face side of rodis the biggest round face),shell box open top wall 2,fillet box edges vertical r 2(alsotop,bottom,all).
Sketches
s = sketch on xy # or: on face 6 of plate offset 2
line (0, 0) to (40, 0) as base_line
rect (0, 0) to (20, 10)
circle (10, 5) r 3 # or d 6
arc (0, 0) from (5, 0) to (0, 5) # centre, start, end; add cw for clockwise
curve (0, 0) (5, 10) (15, 10) (20, 0) # Bézier with two control points
spline (0, 0) (10, 5) (20, 0)
ellipse (0, 0) major (10, 0) minor 4
polygon (0, 0) through (10, 0) sides 6 # add circumscribed
slot (0, 0) to (20, 0) r 4
text "Hello" at (0, 0) height 10 font "Helvetica-Bold" angle 0
point (5, 5)
end
Add construction to a curve to keep it out of profiles. Name a curve with as to use it later: line s.base_line as an axis, or as a path.
Steps
| Command | Example |
|---|---|
| Extrude | extrude s at (5, 5) by 10 symmetric cut into plate · extrude face 3 of plate by 2 |
| Revolve | revolve s at (12, 5) around line s.axis by 270 · around x axis, sketch y, edge 4 of plate |
| Box, cylinder, sphere, torus, coil | box 20, 20, 10 on xy at (0, 0) · cylinder r 5 h 20 · sphere r 10 · torus 15, 4 · coil r 10 pitch 5 turns 4 section 1.5 |
| Fillet, chamfer | fillet plate edges 1, 2 r 2 · chamfer plate edges 5 d 1 |
| Move, copy | move plate by (40, 0, 0) rotate (0, 0, 90) about (0, 0, 0) copy |
| Pattern | pattern peg along x 5 every 12 and y 2 every 20 · pattern peg around z axis 6 over 360 new |
| Scale | scale plate by 2 · scale plate by (1, 1, 0.5) about (0, 0, 0) |
| Combine | combine plate with peg, bolt cut keep |
| Split | split plate with xz offset 4 · with a twist lock (push in, turn): split plate with xy offset 20 twist lugs 3 turn 30 (also size 16, clearance 0.2, count 2, nodetent, unkeyed) · with pins or magnets instead: split plate with xy offset 20 pins 1.75 depth 6 (hole depth in each part), magnets 6 by 2 (Ø by thickness), then fit press, count 2 (per cut face; else one every 40 mm, two at least) · to the bed, pieces that each fit it: split arm with bed 170 by 170 by 170 (the biggest piece: x, y, height), then x 2, y 1, z 1 (pieces along an axis; else as few as fit), nolabels (no A1, A2… on the cut faces) and pins or magnets as above · along sketch curves, with locks: split plate with grid.c1, grid.c2 lock jigsaw size 10 clearance 0.15 · every curve of a sketch: split map with grid lock dovetail size 8 clearance 0.2 every 40 whole · also count 2, tabs left, wall 2, round 0.5, noextend, and changes to single locks: flip 1 at 0.5, remove 2 at 0.3, add 3 at 0.25, move 1 at 0.2 to 0.4 (edge number, then where along it, 0 to 1) |
| Hole | hole on face 6 of plate at (10, 10), (30, 30) diameter 5 depth 8 counterbore 9 by 3 · through · countersink 9 at 90 · flat · tip 118 · on its side: teardrop or flatroof · over a counterbore or nut trap facing the bed: bridge 0.2 · nut trap: nut 5.5 by 2.7 (across flats, depth) · a fit from the list, its gap added on each side of every diameter: fit slide (exact, press, tight, slide, loose, inplace) · what it is for (shown in the panel): for insert "M3 × 5.7" (screw, sockethead, selftapping, insert, nut, magnet) |
| Pipe, sweep, rib | pipe along path.l1, path.l2 diameter 6 wall 1 · sweep s at (0, 10) along path.l1 · rib along s.l1 thickness 2 depth 10 |
| Loft | loft a at (0, 0), b at (0, 0) ruled |
| Emboss | emboss label at (3, 4), (9, 4) depth 1 · add deboss to sink it |
| Shell | shell box1 open 6 wall 2 |
| Mirror | mirror plate across yz · add new to keep it a separate body |
| Thread | thread face 3 of bolt M6 pitch 1 clearance 0.2 length 10 · or fit slide instead of the clearance · other standards instead of M6: unc "1/4-20", unf "#10-32", pipe "G1/2" (BSPP, 55°), bottle (PCO-1881 soda bottle), jar 70 or jar 86 (mason jar 70-450 / 86-450); a number that names no size is the diameter in that standard's shape: pipe 30 pitch 2 |
| Fit | fit is the project's Slide gap (0.2 mm a side plus the printer's offset from the Fit test): cylinder d peg + 2 * fit h 4. Split and twist locks take fit slide instead of clearance |
| Imported mesh | mesh "Bracket.stl" (the mesh stays in the project) |
| Imported STEP | step "Board" (the file stays in the project; each solid is a body) |
| Texture | texture box faces top knurlDiamond depth 0.6 scale 3 · also rotate, seed, margin, solid (real faces and edges: fillet them, sketch on them, export them to STEP) |
| Surface waves | waves box at (0, 0, 10), (20, 5, 10) amplitude 0.8 wavelength 8 · also faces top, decay, phase, solid |
| Smart object | object peg "Peg" … its own script … end |
| Place copies | place peg over plate faces top every 10 inset 3 bind h "5 + d / 10" join into plate · at (x, y, z), … · grid on xy 4 by 3 every 10 |
| Data to 3D | data "Sales" bars cell 5 gap 0.5 height 30 base 2 · surface, columns, log |
| Brim ears | ears plate diameter 10 thick 0.4 |
| Flow lines | flowlines "Shade" radius "60 - 18*t" height 160 lines 24 path "k * p * t" with k 3 from 0.5 to 8 · also one way, phase 7.5, width 2.4, thickness 1.6 both (outward, inward), rims 3 5, detail 0.8, on xy, at (x, y), join into plate. The radius is in mm, of z (mm) and t (0 at the bottom, 1 at the top); the path is in degrees, of t, z, i (the line's number), n (the number of lines) and p (360 / n) |
| Function to body | function "Sombrero" z "sin(r) / r" x -10 to 10 y -10 to 10 width 80 height 20 grid 80 base 2 · parametric "x", "y", "z" u 0 to 2*pi v 0 to 2*pi with R 2, r 1 inside · implicit "F" x … y … z … thickness 1.2 both |
| Gear system | gears "Gearbox" module 2 width 6 layers 2 input at (0, 0) teeth 20 clockwise output 1/4 opposite output 3 same at (70, 20) layer 2 fit slide pin 5 bore round plate 3 margin 6. One output per output: its speed as a number or fraction (out / in), same or opposite, at (x, y) for a fixed axle, layer n; or ring 6 of 1/4 instead: six outputs round the input, every one at that speed, each meshing with the input gear. Then teeth 12 to 80 (the range the solver may use), gap 0.6 (between layers), hole 3 / screw (M3) / filament 1.75 instead of pin, bore d 4.5 / bore hex, no plate, on xz. A layout made by hand follows as shaft 2 at (40, 0) output 1, gear 2 shaft 2 layer 1 teeth 40 idler, mesh 1 2 (numbers from 1). Every shaft becomes a body (its gears fused with a hub), the plate another |
| Map to body | map "tatra.hgt" data width 150 exaggerate 2 base 2 · map "heat.png" colours "Viridis" values 0 to 40 · map "hills.svg" contours interval 10 terraces · map noise ridged seed 48213 size 30 falloff 0.6 width 120 height 20 floor 0.35 shape data · globe r 50 wall 2 |
Function to body
A formula made into a body: z "…" for a graph z = f(x, y) (also r, the distance from the centre), parametric "x", "y", "z" for a surface of u and v, or implicit "F" for F(x, y, z) = 0, inside where F < 0. Formulas are in quotes and use radians, + - * / ^, pi, e, sin cos tan asin acos atan atan2 sinh cosh tanh sqrt abs exp ln log10 min max floor ceil round sign pow hypot clamp, and the fractals mandelbrot(x, y, n), mandelbulb(x, y, z, n, iterations) and julia(x, y, z, a, b, c, d, iterations).
- Ranges:
x -10 to 10 y -10 to 10(graphs),u … v …(parametric),x … y … z …(implicit). - Values the formulas use:
with k 6 from 1 to 20, R 2(the range is the slider's). logplots log(1 + z) for steep functions;widthandheightin mm;gridpoints (or cells).- The body:
base 2,thickness 1.2 below(orabove,both),surfaceorinside; thenon xzoron face 6 of plate,at (10, 0), and how it combines (join into plate). On a face,clipcuts a graph to the face's outline.
Map to body
A map file kept in the project (import it first with Generate → Import Map), or generated noise, made into a relief.
- Values:
grey(white high),grey inverted,data(heights in the file), orcolours from (x, y) to (x, y) values -500 to 4800(the legend's two ends in pixels) orcolours "Turbo" values 0 to 1, withsteppedandtolerance 12. - Contour lines:
map "hills.svg" contours interval 10,terracesfor flat steps,level 3 25for one contour's height. - Generated:
map noise clouds|ridged|billow|cells|craters seed 4 size 20, withoctaves,rough,lacunarity,warp,offset (x, y),tileable,falloff,terraces,cracks,jitter,count 40 radius 1 to 15. Add noise to a file:noise clouds seed 5 size 2 amount 0.02. - Adjust:
crop (0.1, 0.2) to (0.9, 0.8),nodata -9999,floor 0,top 3000,smooth 1,invert. - Size:
width 200orscale 20000000(1 : N),depth(generated),nolongitude,height 10orexaggerate 20,grid 0.25(mm). - Body:
base 2,thickness 1.6 below,surface,globe r 50 wall 2; outlineshape circle,shape data,shape profile s at (0, 0)or, on a body's face (on face 6 of plate join into plate),shape face.