{"id":19069590,"url":"https://github.com/cncjs/gcode-toolpath","last_synced_at":"2025-04-15T17:42:19.252Z","repository":{"id":57245449,"uuid":"49942236","full_name":"cncjs/gcode-toolpath","owner":"cncjs","description":"G-code Toolpath Generator","archived":false,"fork":false,"pushed_at":"2024-11-17T14:48:04.000Z","size":123,"stargazers_count":46,"open_issues_count":0,"forks_count":16,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-11T02:02:01.973Z","etag":null,"topics":["gcode","gcode-toolpath"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cncjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-01-19T09:40:13.000Z","updated_at":"2025-04-08T11:15:55.000Z","dependencies_parsed_at":"2022-09-01T04:31:29.335Z","dependency_job_id":"15d958fe-1998-4aad-a2ba-11bd11342f08","html_url":"https://github.com/cncjs/gcode-toolpath","commit_stats":{"total_commits":72,"total_committers":2,"mean_commits":36.0,"dds":0.02777777777777779,"last_synced_commit":"f40e9f86f006f982eb30a41d4b819226e6091adb"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-toolpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-toolpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-toolpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-toolpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cncjs","download_url":"https://codeload.github.com/cncjs/gcode-toolpath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249121466,"owners_count":21216128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gcode","gcode-toolpath"],"created_at":"2024-11-09T01:14:50.922Z","updated_at":"2025-04-15T17:42:19.240Z","avatar_url":"https://github.com/cncjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcode-toolpath [![codecov](https://codecov.io/gh/cncjs/gcode-toolpath/graph/badge.svg?token=JHJU80PHU8)](https://codecov.io/gh/cncjs/gcode-toolpath)\n\n[![NPM](https://nodei.co/npm/gcode-toolpath.png?downloads=true\u0026stars=true)](https://www.npmjs.com/package/gcode-toolpath)\n\n## Install\n\n`npm install --save gcode-toolpath`\n\n## Usage\n\n```js\nconst Toolpath = require('gcode-toolpath');\n\nconst toolpaths = [];\nconst toolpath = new Toolpath({\n    // Initial position (optional)\n    position: { x: 0, y: 0, z: 0 },\n\n    // Initial modal state (optional)\n    modal: {\n        motion: 'G0', // G0, G1, G2, G3, G38.2, G38.3, G38.4, G38.5, G80\n        wcs: 'G54', // G54, G55, G56, G57, G58, G59\n        plane: 'G17', // G17: xy-plane, G18: xz-plane, G19: yz-plane\n        units: 'G21', // G20: Inches, G21: Millimeters\n        distance: 'G90', // G90: Absolute, G91: Relative\n        feedrate: 'G94', // G93: Inverse time mode, G94: Units per minute, G95: Units per rev\n        program: 'M0', // M0, M1, M2, M30\n        spindle: 'M5', // M3, M4, M5\n        coolant: 'M9', // M7, M8, M9\n        tool: 0\n    },\n\n    // @param {object} modal The modal object.\n    // @param {object} v1 A 3D vector of the start point.\n    // @param {object} v2 A 3D vector of the end point.\n    addLine: (modal, v1, v2) =\u003e {\n        const motion = modal.motion;\n        const tool = modal.tool;\n        toolpaths.push({ motion: motion, tool: tool, v1: v1, v2: v2 });\n    },\n\n    // @param {object} modal The modal object.\n    // @param {object} v1 A 3D vector of the start point.\n    // @param {object} v2 A 3D vector of the end point.\n    // @param {object} v0 A 3D vector of the fixed point.\n    addArcCurve: (modal, v1, v2, v0) =\u003e {\n        const motion = modal.motion;\n        const tool = modal.tool;\n        toolpaths.push({ motion: motion, tool: tool, v1: v1, v2: v2, v0: v0 });\n    }\n});\n\n// Position\ntoolpath.setPosition({ x: 100, y: 10 }); // x=100, y=10, z=0\ntoolpath.setPosition(10, 20, 30); // x=10, y=20, z=30\n\n// Modal\ntoolpath.setModal({ tool: 1 });\n\n// Load G-code from file\nconst file = 'example.nc';\ntoolpath.loadFromFile(file, function(err, data) {\n});\n\n// Load G-code from stream\nconst stream = fs.createReadStream(file, { encoding: 'utf8' });\ntoolpath.loadFromStream(stream, function(err, data) {\n});\n\n// Load G-code from string\nconst str = fs.readFileSync(file, 'utf8');\ntoolpath.loadFromString(str, function(err, data) {\n});\n```\n\n## Examples\n\nRun this example with babel-node:\n```js\nimport Toolpath from 'gcode-toolpath';\n\nconst GCODE = [\n    'N1 T2 G17 G20 G90 G94 G54',\n    'N2 G0 Z0.25',\n    'N3 X-0.5 Y0.',\n    'N4 Z0.1',\n    'N5 G01 Z0. F5.',\n    'N6 G02 X0. Y0.5 I0.5 J0. F2.5',\n    'N7 X0.5 Y0. I0. J-0.5',\n    'N8 X0. Y-0.5 I-0.5 J0.',\n    'N9 X-0.5 Y0. I0. J0.5',\n    'N10 G01 Z0.1 F5.',\n    'N11 G00 X0. Y0. Z0.25'\n].join('\\n');\n\nconst toolpaths = [];\nconst toolpath = new Toolpath({\n    // @param {object} modal The modal object.\n    // @param {object} v1 A 3D vector of the start point.\n    // @param {object} v2 A 3D vector of the end point.\n    addLine: (modal, v1, v2) =\u003e {\n        const motion = modal.motion;\n        const tool = modal.tool;\n        toolpaths.push({ motion: motion, tool: tool, v1: v1, v2: v2 });\n    },\n    // @param {object} modal The modal object.\n    // @param {object} v1 A 3D vector of the start point.\n    // @param {object} v2 A 3D vector of the end point.\n    // @param {object} v0 A 3D vector of the fixed point.\n    addArcCurve: (modal, v1, v2, v0) =\u003e {\n        const motion = modal.motion;\n        const tool = modal.tool;\n        toolpaths.push({ motion: motion, tool: tool, v1: v1, v2: v2, v0: v0 });\n    }\n});\n\ntoolpath\n    .loadFromString(GCODE, (err, results) =\u003e {\n        console.log(toolpaths);\n    })\n    .on('data', (data) =\u003e {\n        // 'data' event listener\n    })\n    .on('end', (results) =\u003e {\n        // 'end' event listener\n    });\n```\n\nand you will see the output as below:\n```js\n[ { motion: 'G0',\n    tool: 2,\n    v1: { x: 0, y: 0, z: 0 },\n    v2: { x: 0, y: 0, z: 6.35 } },\n  { motion: 'G0',\n    tool: 2,\n    v1: { x: 0, y: 0, z: 6.35 },\n    v2: { x: -12.7, y: 0, z: 6.35 } },\n  { motion: 'G0',\n    tool: 2,\n    v1: { x: -12.7, y: 0, z: 6.35 },\n    v2: { x: -12.7, y: 0, z: 2.54 } },\n  { motion: 'G1',\n    tool: 2,\n    v1: { x: -12.7, y: 0, z: 2.54 },\n    v2: { x: -12.7, y: 0, z: 0 } },\n  { motion: 'G2',\n    tool: 2,\n    v1: { x: -12.7, y: 0, z: 0 },\n    v2: { x: 0, y: 12.7, z: 0 },\n    v0: { x: 0, y: 0, z: 0 } },\n  { motion: 'G2',\n    tool: 2,\n    v1: { x: 0, y: 12.7, z: 0 },\n    v2: { x: 12.7, y: 0, z: 0 },\n    v0: { x: 0, y: 0, z: 0 } },\n  { motion: 'G2',\n    tool: 2,\n    v1: { x: 12.7, y: 0, z: 0 },\n    v2: { x: 0, y: -12.7, z: 0 },\n    v0: { x: 0, y: 0, z: 0 } },\n  { motion: 'G2',\n    tool: 2,\n    v1: { x: 0, y: -12.7, z: 0 },\n    v2: { x: -12.7, y: 0, z: 0 },\n    v0: { x: 0, y: 0, z: 0 } },\n  { motion: 'G1',\n    tool: 2,\n    v1: { x: -12.7, y: 0, z: 0 },\n    v2: { x: -12.7, y: 0, z: 2.54 } },\n  { motion: 'G0',\n    tool: 2,\n    v1: { x: -12.7, y: 0, z: 2.54 },\n    v2: { x: 0, y: 0, z: 6.35 } } ]\n```\n\n## G-code Toolpath Visualizer\nCheck out the source code at https://github.com/cncjs/cnc/blob/master/src/web/widgets/Visualizer/GCodeVisualizer.js\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcncjs%2Fgcode-toolpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcncjs%2Fgcode-toolpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcncjs%2Fgcode-toolpath/lists"}