Skip to main content

Translate

translate() moves solids by a distance along the world axes, or adds a moved copy.

There is no Translate dialog in part mode: the statement is written in the editor. In an assembly, instances are moved by dragging the transform gizmo, and the pose is written back as .translate() on the insert() statement.

A spacer slid along the plate onto its stud

The code behind it
spacer.part.js
import { sketch, circle, extrude, translate, line } from 'fluidcad/core';
import { coincident, distance, fix, horizontal, vertical } from 'fluidcad/constraints';

// A base plate with a stud, and a spacer that has to slide onto the stud.
sketch("xy", () => {
const b = line([-50, -30], [50, -30]);
const r = line([50, -30], [50, 30]);
const t = line([50, 30], [-50, 30]);
const l = line([-50, 30], [-50, -30]);
coincident(b.end(), r.start());
coincident(r.end(), t.start());
coincident(t.end(), l.start());
coincident(l.end(), b.start());
horizontal(b);
vertical(r);
horizontal(t);
vertical(l);
fix(b.start(), [-50, -30]);
distance(b.start(), b.end(), 100);
distance(r.start(), r.end(), 60);
});
const plate = extrude(8);

// The stud, on the plate's top face at x = 30.
sketch(plate.endFaces(), () => { circle([30, 0], 10); });
extrude(30);

// The spacer: a ring modelled at x = -30, a separate body.
sketch(plate.endFaces(), () => {
circle([-30, 0], 24);
circle([-30, 0], 10);
});
const spacer = extrude(8).new();

// Slide the spacer 60 along X onto the stud. translate() has no dialog: it
// names its targets (or takes the last object) and adds a step to the timeline.
translate(60, 0, 0, spacer);

Code forms

import { translate } from 'fluidcad/core';

translate(x) // along X only
translate(x, y) // along X and Y
translate(x, y, z) // all three
translate([x, y, z]) // the same, as a point

translate(x, y, z, a, b) // move specific solids
translate(x, y, z, true) // COPY: keep the original, add a moved duplicate
translate([x, y, z], true, target) // copy a specific solid

The trailing targets are optional; without them translate() moves the object built last. The boolean before the targets switches from moving to copying. Distances are in the file's unit.

Positioning parts

Translating a part inside its own file is rarely what you want: a part is authored around its own origin and placed when it is inserted into an assembly. Use translate() for placing bodies relative to each other within one part — a second body kept separate with .new(), an imported STEP file (load()), a primitive.

const l = load("bracket")
rotate("x", 90)
translate(0, -50, 25)