Lets3dPrint

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

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

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

CommandExample
Extrudeextrude s at (5, 5) by 10 symmetric cut into plate · extrude face 3 of plate by 2
Revolverevolve s at (12, 5) around line s.axis by 270 · around x axis, sketch y, edge 4 of plate
Box, cylinder, sphere, torus, coilbox 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, chamferfillet plate edges 1, 2 r 2 · chamfer plate edges 5 d 1
Move, copymove plate by (40, 0, 0) rotate (0, 0, 90) about (0, 0, 0) copy
Patternpattern peg along x 5 every 12 and y 2 every 20 · pattern peg around z axis 6 over 360 new
Scalescale plate by 2 · scale plate by (1, 1, 0.5) about (0, 0, 0)
Combinecombine plate with peg, bolt cut keep
Splitsplit plate with xz offset 4 · with a twist lock (push in, turn): split plate with xy offset 20 twist lugs 3 turn 30 · 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 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)
Holehole 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 facing the bed: bridge 0.2
Pipe, sweep, ribpipe 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
Loftloft a at (0, 0), b at (0, 0) ruled
Embossemboss label at (3, 4), (9, 4) depth 1 · add deboss to sink it
Shellshell box1 open 6 wall 2
Mirrormirror plate across yz · add new to keep it a separate body
Threadthread face 3 of bolt M6 pitch 1 clearance 0.2 length 10
Imported meshmesh "Bracket.stl" (the mesh stays in the project)
Imported STEPstep "Board" (the file stays in the project; each solid is a body)
Texturetexture 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 waveswaves box at (0, 0, 10), (20, 5, 10) amplitude 0.8 wavelength 8 · also faces top, decay, phase, solid
Smart objectobject peg "Peg" … its own script … end
Place copiesplace 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 3Ddata "Sales" bars cell 5 gap 0.5 height 30 base 2 · surface, columns, log
Brim earsears plate diameter 10 thick 0.4
Flow linesflowlines "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 bodyfunction "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
Map to bodymap "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).

Map to body

A map file kept in the project (import it first with Generate → Import Map), or generated noise, made into a relief.