Your first machine

Needs pip install "machinome[viewer,cadquery]".

Ten minutes: a project, one part, one input, and a slider in the browser that moves it.

Create a project

$ machinome new myproject
$ cd myproject

machinome new writes a package with one starter part, a companion test file with two whole-model contracts, a .gitignore and a pyproject.toml manifest naming the model:

[tool.machinome]
model = "myproject.myproject:Myproject"

Start the development loop:

$ machinome develop

and open http://localhost:8000. The viewer shows the starter part, a box with a hole. Every time you save a source file, the parts that changed are rebuilt and the page reloads. Leave it running.

Give it an input

The starter part is a CadQuery part when, as on the installation page’s route, SolidPython is not installed, and a SolidPython part, which needs OpenSCAD, where SolidPython is installed too. Replace the whole of myproject/myproject.py with a CadQuery block and an assembly that lifts it:

import cadquery as cq

from machinome.node.assembly import AssemblyNode
from machinome.node.cadquery import CadQueryNode
from machinome.simulation import Driver


class Block(CadQueryNode):

    def render(self):
        return (cq.Workplane('XY')
                .box(50, 50, 50, centered=(True, True, False))
                .faces('>Z').workplane().hole(20))


class Lifter(AssemblyNode):

    lift = Driver(default=0.0, range=(0.0, 80.0), unit='mm')

    block = Block()

    def simulate(self):
        self.block.translate([0, 0, self.lift])

Then point the manifest at the assembly:

[tool.machinome]
model = "myproject.myproject:Lifter"

Save. The viewer now shows the block and a lift slider. Drag it and the block rises.

Three things happened in those twenty lines:

  • Block is a leaf: its render() returns a solid from a modelling library, and the framework builds the part from it.

  • Lifter is an assembly. block = Block() declares a child; the assembly places it. lift is a driver: a named input with a default, a range for the slider, and a unit.

  • simulate() is where the input is read. It runs on every instant with self.lift bound to whatever the slider holds, and the translation it applies is that instant’s motion. The expression travels into the published model unevaluated, so dragging the slider moves the block without running any Python.

The starter test file still works: its two contracts check that every printed piece is one body and that no two pieces interfere. Run them:

$ machinome test

Look in the build directory

_build/ holds what the build produced: an STL per part, a .brep beside it with the B-rep geometry of a B-rep part, and the viewer.json document that the viewer reads. Nothing in it is edited by hand.

Next

The tutorial builds a machine that counts: a crank, two digit drums, the relations between them, the tests that prove the fit, and the memory that makes it a counter. Each chapter ends with a machine you can drive.