├── .gitignore ├── test └── star.svg ├── package.json ├── readme.md └── bin └── svg2gcode /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /test/star.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "svg2gcode", 3 | "version": "0.0.4", 4 | "description": "Convert SVG to Gcode", 5 | "bin": { 6 | "svg2gcode": "./bin/svg2gcode" 7 | }, 8 | "dependencies": { 9 | "canvg": "0.0.6", 10 | "commander": "^2.5.0", 11 | "gcanvas": "0.0.*" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "em/svg2gcode" 16 | }, 17 | "keywords": [ 18 | "svg", 19 | "gcode", 20 | "cnc", 21 | "milling" 22 | ], 23 | "author": "Emery Denuccio", 24 | "license": "MIT" 25 | } 26 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | svg2gcode 2 | ======== 3 | A command line utility for converting SVG to Gcode using [Gcanvas](https://github.com/em/gcanvas) and [canvg](https://code.google.com/p/canvg/). 4 | 5 | ### Installation 6 | First make sure you have [nodejs](http://nodejs.org) installed. 7 | ``` 8 | npm install -g svg2gcode 9 | ``` 10 | 11 | ### Usage 12 | ``` 13 | Usage: svg2gcode [options] 14 | 15 | Options: 16 | 17 | -h, --help output usage information 18 | -V, --version output the version number 19 | -s, --speed spindle speed 20 | -f, --feed feed rate 21 | -d, --depth z of final cut depth 22 | -c, --depthofcut z offset of layered cuts 23 | -t, --top z of top of work surface 24 | -a, --above z of safe area above the work 25 | ``` 26 | -------------------------------------------------------------------------------- /bin/svg2gcode: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs') 4 | , program = require('commander') 5 | , GCanvas = require('gcanvas') 6 | , canvg = require("canvg"); 7 | 8 | program 9 | .version(require('../package.json').version) 10 | .usage('[options] ') 11 | .option('-s, --speed ', 'spindle speed', eval) 12 | .option('-f, --feed ', 'feed rate', eval) 13 | .option('-d, --depth ', 'z of final cut depth', eval) 14 | .option('-c, --depthofcut ', 'z offset of layered cuts', eval) 15 | .option('-t, --top ', 'z of top of work surface', eval) 16 | .option('-a, --above ', 'z of safe area above the work', eval) 17 | .option('-D, --tooldiameter ', 'diameter of tool', eval) 18 | .option('-p, --positive', 'Treat fill as positive, cutting only around the outside') 19 | 20 | program.parse(process.argv); 21 | 22 | var gctx = new GCanvas(); 23 | 24 | if(program.speed) gctx.speed = program.speed; 25 | if(program.feed) gctx.feed = program.feed; 26 | if(program.depth) gctx.depth = program.depth; 27 | if(program.depthofcut) gctx.depthOfCut = program.depthofcut; 28 | if(program.top) gctx.top = program.top; 29 | if(program.above) gctx.aboveTop = program.above; 30 | if(program.tooldiameter) gctx.toolDiameter = program.tooldiameter; 31 | 32 | if(program.positive) { 33 | 34 | gctx.fill = function(windingRule, depth) { 35 | gctx.save(); 36 | gctx.strokeStyle = gctx.fillStyle; 37 | gctx.stroke('outer', depth); 38 | gctx.restore(); 39 | } 40 | } 41 | 42 | 43 | function run(file) { 44 | var svg = ''+fs.readFileSync(file); 45 | canvg(gctx.canvas, svg); 46 | console.log('M30'); 47 | } 48 | 49 | if(program.args.length === 0 && process.stdin.isTTY) { 50 | program.outputHelp(); 51 | process.exit(0); 52 | } 53 | if(!process.stdin.isTTY) { 54 | run('/dev/stdin'); 55 | } 56 | 57 | program.args.forEach(function(file) { 58 | run(file); 59 | }); 60 | 61 | if(program.top > 0) { 62 | gctx.motion.rapid({z:0}); 63 | } 64 | else { 65 | gctx.motion.retract(); 66 | } 67 | 68 | 69 | // process.exit(0); 70 | --------------------------------------------------------------------------------