param()
Declares a named parameter and returns its current value. The control is inferred from the default: a boolean becomes a checkbox, a number a number field, a string a text field.
A parameter belongs to a part(...) (or assembly(...)) body — declare it
at the top of the callback, before the geometry that reads it. Called
outside every body it is an error — a model file has no parameters of its
own — unless the file is a *.params.js module: a parameter exported from
there is a project parameter, shared with every file that imports it and
edited in the Parameters panel, where its value is its declared literal.
When the defining file renders, the parameter appears in the Parameters
panel under its part, and a value edited there is written back as the new
default. Inserted elsewhere, the same declaration is the definition's
parameter interface: insert(def, { Length: 380 }) supplies the value per
instance, and the Insert dialog builds that object from these
declarations.
Returns: number | string | boolean
See the guide for detailed usage examples.
Signatures
param(label: string, defaultValue: T): T
Declares a named parameter and returns its current value. The control is inferred from the default: a boolean becomes a checkbox, a number a number field, a string a text field.
A parameter belongs to a part(...) (or assembly(...)) body — declare it
at the top of the callback, before the geometry that reads it. Called
outside every body it is an error — a model file has no parameters of its
own — unless the file is a *.params.js module: a parameter exported from
there is a project parameter, shared with every file that imports it and
edited in the Parameters panel, where its value is its declared literal.
When the defining file renders, the parameter appears in the Parameters
panel under its part, and a value edited there is written back as the new
default. Inserted elsewhere, the same declaration is the definition's
parameter interface: insert(def, { Length: 380 }) supplies the value per
instance, and the Insert dialog builds that object from these
declarations.
| Parameter | Type | Description |
|---|---|---|
label | string | The parameter's name — what the panel shows and the key an override uses. Unique within a part. |
defaultValue | T | The value used when nothing overrides it. |
param(label: string, defaultValue: T, type: K, options?: ParamOptionsMap[K]): T
Declares a named parameter with an explicit control and its options.
const length = param('Length', 150, 'number', { min: 20, max: 2000, step: 10 });
const bore = param('Bore', 4.2, 'slider', { min: 3, max: 8, step: 0.1 });
const finish = param('Finish', 'anodised', 'select', {
options: [{ label: 'Anodised', value: 'anodised' }, { label: 'Raw', value: 'raw' }],
});
const rounded = param('Rounded corners', true, 'checkbox');
const tint = param('Body colour', '#4a90d9', 'color');
| Parameter | Type | Description |
|---|---|---|
label | string | The parameter's name and override key. |
defaultValue | T | The value used when nothing overrides it. |
type | K | The control: 'number', 'slider', 'text', 'select', 'checkbox' or 'color'. |
options | ParamOptionsMap[K] | Per-type options: min / max / step for number and slider, options (plus multi, multiControlType) for select; every type takes group and description. (optional) |
param(label: string, defaultValue: (string | number)[], type: 'select', options: SelectParamOptions & { multi: true }): (string | number)[]
Declares a multi-select parameter: the value is the array of chosen option
values. multiControlType picks how it is shown — 'select',
'checkboxes' or 'chips'.
| Parameter | Type | Description |
|---|---|---|
label | string | The parameter's name and override key. |
defaultValue | (string | number)[] | The option values selected by default. |
type | 'select' | Always 'select'. |
options | SelectParamOptions & { multi: true } | options to choose from, with multi: true. |