Skip to main content

Creating a part container

Over the next eight pages you build a butt hinge: two leaves with interleaving knuckles, a pin through them, and a joint that swings the hinge open and shut.

The finished hinge

Every page ends with a picture like this one; press play on it to load that step into the browser viewer, spin it around, and open its files.

This page creates the file for the first leaf and puts a part container in it.

Do you need a part container?

A .part.js file can hold bare modelling statements. Sketch, extrude, fillet at the top level and the file renders. The part() container is optional for a part you only ever look at on its own.

It is required as soon as the part is going to be inserted into an assembly. An assembly imports the file and inserts an exported part definition, so the leaf needs export const fixedLeaf = part('Fixed leaf', () => { … }) around its features. The container is also what parameters, connectors and exposed geometry attach to. Since this leaf ends up in a hinge, start with the container.

In the viewport

  1. Click + at the end of the tab strip. A box opens with every file in the workspace; type a name that does not exist yet, hinge-leaf-fixed.part.js, and press Enter. The file is created and opens as a tab. (Any editor works too: the server watches the folder.)
  2. Click Part on the toolbar. It appends an empty part to the file and the History panel shows a Part 1 row.
  3. Right-click the row and choose Rename. Type Fixed leaf. The name is written into the part('…') statement and becomes the part's display name everywhere: the History panel, the assembly's Parts list, the STEP export.
  4. Open the code editor (the </> button on the left rail, or Ctrl+B) and add export const fixedLeaf = in front of the statement. The export is the one thing the toolbar does not write for you, and it is what the assembly will import later.

Nothing renders yet: the part is empty. The History panel shows the part row, and every feature you add from now on lands inside it.

The code behind it
hinge-leaf-fixed.part.js
import { origin, xAxis, yAxis, part, sketch, line, circle, extrude, cut, repeat, fillet, connector } from 'fluidcad/core';
import { coincident, horizontal, vertical, midpoint, distance, diameter, fix } from 'fluidcad/constraints';
import { edge } from 'fluidcad/filters';

// The part container: everything inside the callback belongs to the
// "Fixed leaf". Exporting it is what lets an assembly insert() it later.
export const fixedLeaf = part('Fixed leaf', () => {
});
note

Statements you add while a part row is active go inside that part. The active part is the highlighted row in the History panel; click a part row to make it active.

Next: Creating a basic sketch.