Skip to content

Latest commit

 

History

History
265 lines (175 loc) · 11.3 KB

README.md

File metadata and controls

265 lines (175 loc) · 11.3 KB

@jscad/cli : OpenJSCAD Command Line Interface

This is the CLI (command line interface) package for OpenJsCAD for server-side computations with NodeJS.

OpenJSCAD

npm version Build Status stability-stable

Dependency Status devDependency Status lerna

Backers on Open Collective Sponsors on Open Collective

Table of Contents

Usage

Install node.js

IMPORTANT: you need a recent , LTS version of Node.js > 6.x.x we test OpenJSCAD on node.js version 6.x.x and above all other versions are not guaranteed to work !

An easy way to install any Node.js version is to use NVM

  • after installing nvm type nvm install v8 (recomended)
  • then nvm use v8

Install OpenJSCAD CLI:

CLI(command-line interface) use

 npm install -g @jscad/cli

Using the CLI

  • simply run openjscad <InputFile> <options> <OutputFile>

examples :

openjscad example005.jscad # -- creates example005.stl as default

openjscad example001.jscad -o test.stl

openjscad example001.scad -o example001scad.jscad # -- convert .scad into .jscad

openjscad frog.stl -o test.jscad # -- convert .stl into .jscad

openjscad logo.jscad -of amf # -- convert logo.jscad into logo.amf

  • you can also provide the parameters to your script directly by passing -- to the cli

openjscad name_plate.jscad --name "Just Me" --title "Geek" -o output.stl

Using with the provided examples

get the examples

  • via git
 git clone git@github.com:jscad/OpenJSCAD.org.git
 cp -r OpenJSCAD.org/packages/examples . 

  • via npm
 npm install @jscad/examples
 cp -r node_modules/@jscad/examples .

run them through the CLI

% cd examples/
% openjscad example005.jscad                         # -- creates example005.stl as default
% openjscad example001.jscad -o test.stl
% openjscad example001.scad -o example001scad.jscad  # -- convert .scad into .jscad
% openjscad frog.stl -o test.jscad                   # -- convert .stl into .jscad
% openjscad logo.jscad -of amf                       # -- convert logo.jscad into logo.amf

Using the CLI on designs created as node modules

You can also run JSCAD designs created as node modules/npm packages through the CLI:

see examples/module-design for such a design

  • install the design using npm :

npm install <PATH TO DESIGN FOLDER>

  • then just pass the folder containing your design to the CLI

openjscad <PATH TO DESIGN FOLDER> <OPTIONS>

  • or run the CLI on the main file if you know which one it is

openjscad <PATH TO DESIGN FOLDER>/index.js <OPTIONS>

Note: when passing a folder to the CLI, it will:

  • first check if there is a package.json file in the folder and try to use its "main" field
  • if that does not work if it will try to look for index.js/jscad, main.js/jscad or a file with same name as the folder

About designs created as node modules (recomended for the future)

You have to deal with your dependencies yourself, NO code is injected 'magically' / globals this means you have to import the design API yourself (this will be the case for all designs in the future, including the in-browser playground)

ie you should have things like this at the top of your design file(s)

use what you need, this is just an example :)

const {color} = require('@jscad/csg/api').color
const {cube, sphere, cylinder} = require('@jscad/csg/api').primitives3d
const {square, circle} = require('@jscad/csg/api').primitives2d
const {linear_extrude} = require('@jscad/csg/api').extrusions
const {union, difference} = require('@jscad/csg/api').booleanOps
const {translate} = require('@jscad/csg/api').transformations

//then use the functions above
const main = (parameters) => {
  return [
    union(cube(), sphere({r: 10})),
    difference(sphere(), color([1, 0, 0], cylinder()))
  ]
}

const getParameterDefinitions = () => {
  return []
}


module.exports = {main, getParameterDefinitions}

The main and getParameterDefinitions functions should be exported in the following manner:

module.exports = {main, getParameterDefinitions}

you can find out more on node modules in the official docs here or with this nice presentation

Development

  • create a base directory
  • clone the base repository git clone https://github.com/jscad/OpenJSCAD.org.git
  • go into OpenJSCAD.org folder cd OpenJSCAD.org
  • install dependencies & setup inter package links npm run bootstrap
  • go into the cli folder: cd packages/cli
  • you can change the code , and run the cli again as you see fit node cli.js <params>

Note : you can also change the code in all the other packages/xxx folders and it will also impact the cli (ie : if you make changes to packages/core in parts that are used in the CLI, you do not need to run additional commands)

Documentation

Contribute

OpenJSCAD.org is part of the JSCAD Organization, and is maintained by a group of volunteers. We welcome and encourage anyone to pitch in but please take a moment to read the following guidelines.

Thank you to all the people who have already contributed to this project:

  • If you want to submit a bug report please make sure to follow the Reporting Issues guide. Bug reports are accepted as Issues via GitHub.

  • If you want to submit a change or a patch, please see the Contributing guidelines. New contributions are accepted as Pull Requests via GithHub.

  • We only accept bug reports and pull requests on GitHub.

  • If you have a question about how to use the OpenJSCAD.org, then please start a conversation at the OpenJSCAD.org User Group. You might find the answer in the OpenJSCAD.org User Guide.

  • If you have a change or new feature in mind, please start a conversation with the Core Developers and start contributing changes.

Small Note: If editing this README, please conform to the standard-readme specification.

Community

See for more details

Acknowledgements

OpenJSCAD and its sub components are built upon great open source work, contribution & modules

  • csg.js core & improvements by Evan Wallace, Eduard Bespalov, Joost Nieuwenhuijse, Alexandre Girard

For input/output

Tooling:

and many more!

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

The MIT License (MIT) (unless specified otherwise)

See Also

  • OpenJsCAD, starting point of OpenJSCAD.org
  • OpenSCAD.net, another place of inspiration, where the OpenSCAD translator was adapted from
  • CoffeeSCad, JavaScript simplified (no more {}) (defunct)
  • stl2pov to convert .stl to .pov, and then render via PovRay.org
  • P3D STL/AMF/OBJ viewer

That's all for now,

Rene K. Mueller, Jeff Gay, Mark Moissette & JSCAD Organization