You know you want to use them

Script parts

Write a part in JavaScript or TypeScript. The numbers and switches you declare become controls that anyone can adjust.

A script part is a part you write in code. It's a short ManifoldCAD-style ES module that returns a solid. Any parameters you declare (sizes, counts, angles, on/off toggles) show up as normal sliders, number fields and switches, so whoever uses the part can adjust it without reading the code.

Use one when a shape is really a loop and a formula: gears, lattices, pegboard and Gridfinity grids, threads. Changing a parameter rebuilds the part immediately.

The script editor with code, parameters and a live preview
Overview. A script part with its code, parameters, and live preview.

How to use it

  1. Create the part

    In the Parts panel, click the New script part tile (or run File ▸ New script part… from the File menu or command palette). Name the part and click Create.

  2. Open the editor

    The script editor opens as a docked panel. On the left are the part's Label, Icon, Shape ID, Description, Tags and Parameters list. On the right is the code editor, with a Live preview underneath.

  3. Start from an example

    To start from working code, open the Examples tab and pick a template (Centered cube, Rounded box, Polygon prism, Revolved vase, Pegboard tile, Spur gear, Gridfinity bin, and more).

  4. Write the module

    Import the geometry API and your parameters, then export default a solid. For example:

    import { Manifold } from 'manifold-3d/manifoldCAD';
    import params from 'cubbycad:params';
    const size = Number(params.size) || 10;
    export default Manifold.cube([size, size, size], true);

  5. Define parameters

    Under Parameters, click Add parameter and fill in a Key (e.g. radius), a Label, a Type (Number, Integer, String, Boolean, or Enum) and a Default. Numeric types also take Min, Max, Step and Unit. Read each value in code with params.<key>.

  6. Watch the preview

    The Live preview shows building…, then ready, and prints any build or validation errors in red.

  7. Save the part

    Click Create script (or Save changes when editing) to save the part to your workspace, then Close to leave the editor.

  8. Place an instance

    Drag the part's tile from the Parts panel into the viewport. Select the instance to adjust its parameters in the properties panel.

A placed script part with its parameters in the Properties panel
In the editor. Declared parameters surfaced as sliders on the placed part.

Tips

  • Scripts use the same dialect as manifoldcad.org, so scripts from there usually paste in with little or no change. Use Manifold for 3D primitives and booleans (subtract, add, hull) and CrossSection for 2D profiles you extrude or revolve.
  • You can export default one solid or an array of solids. An array gets unioned, which is handy for things built in a loop.
  • TypeScript works. Type annotations are stripped before the script runs, and top-level await is allowed.
  • Only two imports are allowed: manifold-3d/manifoldCAD and cubbycad:params. Anything else is a hard error, and only export default is recognized. Scripts run in a sandbox with no network or DOM access.
  • Give parameter reads a fallback (Number(params.size) || 10) so a blank or out-of-range value doesn't break the build.
  • The Shape ID is locked after the first save so existing scenes can still find the part. Pick it carefully.

Try it yourself

Open the editor and start from one of the script examples.