Skip to main content

Part parameters

A part declares its parameters with param(). Inserted into an assembly, that list is the part's interface: every insert() can supply its own values, and the same definition builds one variant per distinct set of values. The assembly can also declare its own parameters and pass them to its instances.

In the viewport​

  1. Click Insert and queue the parts. A tile shows how many parameters its part declares; click it once per instance you want. If a queued part declares parameters, Next leads to a parameters page before inserting: one form per queued instance, with the same controls the part's Parameters panel shows (number fields, sliders, selects, checkboxes, colour swatches). Two queued plates can get two widths. Leave a control alone and the part's default applies.

    The Insert dialog's parameters page, one form per queued plate

  2. Click Insert N. Every instance is written as one insert() statement; only the values you changed go into its second argument:

    const plate1 = insert(plate, { Width: 120, Hole: 6.6 });
    const plate2 = insert(plate, { Width: 60, Depth: 40 });
  3. To change an instance later, open its row menu in the Parts panel (right-click, or ⋮) and choose Edit parameters…. The dialog opens on the instance's current values and merges what you change into the statement; the arrow beside a row puts that value back to the part's default. Only the labels you touch are rewritten; an entry you leave alone keeps whatever the source says, an expression included.

    The Edit parameters dialog on an inserted plate
  4. Both Insert and Edit parameters support expression inputs. Number fields accept assembly parameters and expressions such as width / 2, with variable suggestions as you type. For sliders, text, selects, checkboxes, and colours, click fx to enter an expression. An existing expression is shown as source text when you reopen the dialog.

In code​

The second argument of insert() maps parameter labels to values:

insert(plate, { Width: 120, Hole: 6.6 });
ControlValue to pass
number, slidera number
texta string
selectone option's value; with multi: true, an array of them
checkboxtrue or false
colora CSS colour string
  • A label you omit keeps the default declared in the part file.
  • A label the part never reads is reported as a warning when the assembly builds, not an error, so a renamed parameter cannot silently break the assembly.
  • Numbers are read in the part file's unit. { Length: 10 } on a part modelled in inches means 10 in, whatever the assembly's project unit is. See Units.
  • Values can be expressions: an override may name a variable of the assembly file, including one of the assembly's own parameters.

Variants share builds​

insert(def) and insert(def, { Width: 120 }) are two builds of the part; two insert(def, { Width: 120 }) share one. Repeating an instance is therefore cheap, and a change to one instance's values never rebuilds the others.

Reading a part's properties​

Values flow the other way too. A part publishes what it computes with property(), and every instance carries the values its own overrides produced, as instance.properties.<name>:

const housing = insert(housingDef, { Width: 100 }).grounded();
insert(plate, { Width: housing.properties.pocketDiameter - 0.4 })
.translate(0, 0, housing.properties.pocketDepth);

They are plain values, so they go anywhere a number goes: a pose, a mate offset, another insert's override. Numbers arrive in the part file's unit, like parameter overrides.

Assembly parameters​

param() is also legal at the top of an assembly() body, where it is the assembly's own value: the inserts below can pass it on, and a sub-assembly declared this way has a parameter interface of its own, overridden exactly like a part's — insert(stack, { Levels: 4 }). The Insert dialog shows the same parameter page for a queued sub-assembly as for a part. Use the assembly workspace's Parameters panel to change their values. Click + to declare a parameter inside the assembly body, or the pencil beside a parameter to edit its declaration — a new label renames the variable and its reads, and a delete puts the default value in their place. This panel manages only the current assembly, so it has no part selector. New declarations require a single assembly() callback body in the current file.

Two plates and a sub-assembly, each insert with its own parameter values

Overrides per instance and a parametric sub-assembly

plate is the mounting plate from the Param page; its parameters are Width, Depth, Thickness, Hole and Chamfer top edges.

frame.assembly.js
import { assembly, insert, param } from 'fluidcad/core';
import { plate } from './plate.part.js';

// A parametric sub-assembly: a column of plates. Its own param() is the
// interface a parent overrides — insert(stack, { Levels: 4 }).
const stack = assembly('stack', () => {
const levels = param('Levels', 3, 'number', { min: 1, max: 6, step: 1 });
insert(plate, { Width: 60, Depth: 40 }).grounded();
for (let i = 1; i < levels; i++) {
insert(plate, { Width: 60, Depth: 40, 'Chamfer top edges': false }).translate(0, 0, i * 20);
}
});

export const frame = assembly('frame', () => {
// The assembly's own parameter — shown in its Parameters panel and
// passed on to the inserts below.
const rail = param('Rail width', 120, 'number', { min: 80, max: 200, step: 10 });
// Overrides are keyed by the part's labels. These two share one build.
insert(plate, { Width: rail, Hole: 6.6 }).grounded();
insert(plate, { Width: rail, Hole: 6.6 }).translate(0, 70, 0);
// A different set of values is a second variant of the same part.
insert(plate, { Width: 60, Depth: 40, Thickness: 4 }).translate(rail / 2 + 50, 35, 0);
// The sub-assembly's parameter, overridden the same way.
insert(stack, { Levels: 4 }).translate(-(rail / 2 + 50), 35, 0);
});