Skip to main content

API, CLI, Embedding

Javascript Slicer Engine

The latest slicing engine code is served live at https://grid.space/code/engine.js

This can be embedded in your page then accessed with the API calls defined on the Engine APIs page.

Command Line API

The slicer engine is also available as a command-line utility

node src/kiri-run/cli --help

cli <options> <file>
--verbose | enable verbose logging
--dir=[dir] | root directory for file paths (default: '.')
--model=[file] | model file to load (or last parameter)
--source=[file] | source file list (defaults to kiri engine)
--device=[file] | device definition file (json)
--process=[file] | process definition file (json)
--controller=[file] | controller definition file (json)
--output=[file] | gcode output to file or '-' for stdout
--position=x,y,z | move loaded model to position x,y,z
--rotate=x,y,z | rotate loaded model x,y,z radians
--scale=x,y,z | scale loaded model in x,y,z
--move=x,y,z | move loaded model x,y,z millimeters

Example Device and Process settings which are defined in init.js around line 250

JSON dictionaries can be used for reference from the CLI package

Embedding Kiri:Moto with an IFrame

Kiri:Moto is designed to be embedded in a page using an IFrame. The look and feel and other controls are available for the loaded page using a messaging API. An example page is here.

functiondescription
setFrame(id_obj)id or object of IFrame with Kiri:Moto loaded
load(url)load an STL referred to by url
clear()remove all objects from workspace
parse(data)parse the text or binary contents of an STL file
setMode(mode)where mode comes from:[ "CAM", "FDM", "LASER", "SLA" ]
setDevice(options)change default Device options
setProcess(options)change default Process options
setController(options)change default Core options
slice()async slice of loaded object
prepare()async path routing of slice data
export()async gcode generation from routed paths
onmessage(fn)function will receive all IFrame messages
onevent(event, data)function will receive named messages
emit(event, data)send named event with data payload
alert(msg, time)show alert message with optional time in seconds
process(percent, message)set progress bar (0.0 to 1.0) with optional message

Events

KeyOutputDescription
animateCNC Animation Started
boolean.updateBoolean checkbox values sync'd
code.loadGCode or SVG code is being loaded / parsed
code.loadedGCode / SVG code parsing complete
device.setA new machine / device was selected
exportGCode / SVG export dialog is open
help.showA Help dialog is open
init-doneApp is fully initialized
init.oneApp is starting to initialize
init.twoApp is binding UI elements
key.esc[ESC] key was pressed
keypressA non-control or meta key was pressed
load.libA script extension was loaded
modal.showA modal dialog is showing
mode.setApp mode changed: FDM, CNC, Laser, SLA
mouse.hoverMouse is hovering over a feature of interest
mouse.hover.downMouse down on a feature of interest
mouse.hover.upMouse up on a feature of interest
platform.layoutPlatform auto-layout was performed
preview.beginPreview Mode calculations started
preview.endPreview Mode calculations complete
preview.errorPreview Mode calculations encountered an error
printLegacy: same as preview.end
range.updatesFDM Range records were changed
reloadApp page will reload in 100ms
resizeApp page was resized
selection.dragGenerated during object drag
selection.moveAfter object drag completes
selection.rotateSelected objects were rotated
selection.scaleSelected objects were scaled
settingsSettings object changed
settings.loadSettings object was replaced
settings.savedSettings object was saved
sliceDeprecated
slice.beginSlicing calculations started
slice.endSlicing calculations complete
slice.errorSlicing calculations encountered and error
slider.labelSlider labels changed
slider.posSlider position changed
slider.setSlider values changed
view.setView mode changed: slice, preview, animate
widget.addAn object was added to the workspace
widget.deleteAn object was deleted from the workspace
widget.deselectAn object was de-selected
widget.rotateAn object was rotated
widget.selectAn object was selected