Inkscape is a powerful Open Source 2D drawing package. Among other capabilities, it is a fully-functional 2D CAD program. You can think of it as either a drawing package that uses the Scalable Vector Graphics (SVG) format as its native format, or as a graphical editor for SVG files. It is easy to add extensions to Inkscape for special functions.
There are two separate extensions to Inkscape to create gcode. The newer extension is called "Gcodetools"and the older extension is called "gcode." both extensions work. This page describes both ways to convert Inkscape paths to gcode files. Gcodetools has been accepted into the main code base of Inkscape and will be available without any extra effort starting with the 0.48 release.
In addition to the two extensions within Inkscape, it is also possible to use external gcode generators such as pyCAM. Some external convertors can handle .svg files directly. For other convertors, Inkscape can export to various formats, including .dxf.
- Inkscape is a 2D vector drawing program that can be used for drafting
- Paths are the drawing elements.
- Inkscape can manipulate bitmaps, fonts and objects, all of which can be converted to paths.
- Inkscape can operate in "pixels", "millimeters", or "inches".
Gcodetools
Setup of Inkscape (and Gcodetools scripts) on Ubuntu
- From Ubuntu package manager, install Inkscape or just run in console 'sudo apt-get install inkscape'
- Get the latest version of Gcode Tools (extensions.tar.gz) from [here] for English users, and [here] for Russian users.
- Unpack it
- With root priviledges, copy the following files to your /usr/share/inkscape/extensions directory (for Windows it's \Program Files\Inkscape\share\extensions\).
- gcode_tools.inx
- gcode_tools.py
How it works
- This extension converts paths that are selected to Gcode. Paths are converted using biarc interpolation, which means that each segment of path interpolates by two arcs (two G02 or G03 code lines). If it's necessary instead of biarc simple straight interpolation is used.
Simple tutorial
Here's simple tutorial how to convert path to Gcode:
- Firstly you have to get some drawings
- You can find some ready svg files (like I did)
- You can draw it by yourself
- Make sure that all objects are paths
- Select all objects and look at the status bar at bottom of window what is selected if it says something like "2 objects of type Path" it is fine
- Otherwise:
- Repeat Object->Ungroup (Shift+Ctrl+G) until there's no more groups in the selection
- Then Path->Object to Path
- Repeat if necessary
- Once all objects in the selection are paths do Extensions->Gcode tools
- Fill in some parameters
- Filename and dir (If selected directory contains 'header' or 'footer' file they will be used as header and footer for your Gcode)
- Units
- Select "Curve to Gcode"
- Press Apply
You will get a new group that contains a kind of preview of generated Gcode (straight lines (G01) are painted in red, arcs (G02 and G03) are painted in blue and green).
And of course you will get your Gcode file in the selected directory.
Here are some illustrations.
This tutorial does not cover all functions of the extension, there are much more of them such:
- Scaling and offsetting
- Multi-pass cutting
- Area cutting
- etc ...
All manuals, tutorials and source codes are available here:
Second way using gcode extension
Setup of Inkscape (and gcode scripts) on Ubuntu
- From Ubuntu 6.06's package manager, install Inkscape 0.43
- With root privileges, copy the following files
to your /usr/share/inkscape/extensions directory. Rename those files to gcode.inx and gcode.py.
- Enable effects: In Inkscape, open the preference page (SHIFT+CTRL+P), select the misc tab and check "Enable script effects".
-
- Restart Inkscape, you should now see a "Effects" menu with a "Export as GCODE" entry
How it works
- The idea is that the "Effect" will generate a gcode file (inch mode) for the SELECTED PATHS
- SELECTED: if nothing is selected, you get a useless gcode file
- PATHS: this effects works only on paths, so "objects" must be "converted to paths" (SHIFT+CTRL+C) and "text" must be converted to paths, bitmaps must be traced (SHIFT+ALT+B), groups must be "ungrouped" etc.
- Styles, strokes, color and other properties are ignored.
- Paths are converted to straight lines using G01 codes.
- This seems is perhaps a huge limitation
- One reason is that the author is very lazy,
- He doesn't understand Bezier maths and control points
- There are too many tunable parameters (how many segments to use, etc)
- He found out that Inkscape has great tools to add/remove nodes.
Tutorial
- Draw a shape (or object, text etc... but don't forget to convert to shape) ... like this:
- Don't use the "Export as GCODE" effect just yet, or you'll get a result like that:
- Use the "Add nodes" effects to control the fidelity of your GCODE. You can also select nodes and the "make selected segments lines" tool to have the best idea of what your shape will look like.
- Select the "Export as GCODE" effect from the "Effect" menu, and go wild on the effects parameters.
- Voila, an easy way to go from vector to EMC.
Feedback
Please edit this section of the page to provide feedback. In particular, I am interested in finding out if it would be best to add a curve interpolation to the effect.
- Pros
- The paths would be kept simple in the svg file, because node count could be limited.
- The GCODE would "look" better, and SVG files would not require editing. This is good for clipart, where the author is not the machinist.
- SVG paths are supposed to be "curvy". Using them as straight segments is an ugly hack.
- I'd disagree, CNC (including EMC) moves in very short straight lines at the lowest level, so making the line segment very short approaches or surpasses the granularity of the trajectory planner. This makes the path as true to the original as possible. It makes a long program of tiny moves. Caveat: if you choose a unit length (1) be prepared for Inkscape to 'go away' for a while, it does not show a 'busy' indication. ;)
- i double dog disagree. any curve interpolation should use [biarcs] - emc supports arc interpolation and we might as well use it. this would keep it 'curvy' but still limit the number of lines to a reasonable amount, and as a bonus you get a perfectly smooth acceleration profile. using line segments clogs the tp queue (slows machine down) and will never approach the same level of smoothness as a biarc path.
- Cons
- The effect would have to make decisions about how many lines should be used in each curve segments, and the magic numbers or unintuitive parameters would have to be typed in (aka: 'precision', 'quality', 'longest segment length'), or derived by the script (with heuristics to decide the 'straightness' of a segment based on its length and control points).
- Unlike other vector to GCODE converter scripts, the user has a good control on the output. He can decide exactly how many segments he wants, because Inkscape has a good set of node editing tools. It gives the user the ultimate control, because he is not a victim of a converter's built in assumptions (a.k.a magic numbers).
- Using a custom interpolation scheme could sometimes produce results that are different to the original. As a result, path intersections may look different in the GCODE than on the SVG application.
- If Inkscape's skew transforms are applied, the output is not transformed. I chose a spiral, stretched it, chose translate|rotate 45 deg, path|object to path, effects|add nodes, length 1.0, effect|export as gcode, chose 0 offsets , pushed it thru sim-servo (axis) and it's not rotated or stretched. The nodes are contained in a 'g', and the 'g' is wrapped in the transforms. Looking at the nodes will overlook the transforms. This is like mirroring and scaling on a cnc, the path is the same gcode, but the gcode is wrapped in a scale or rotate.
- I have patched [gcode.py] and [gcode.inx] in order to consider the scale and translation specified in the path transformation matrix.I have converted also the units and the output gcode in metric scale.
Perhaps the best approach is some kind of middle ground.
GlenHarris?: I have modified these scripts to create a slightly different version. This version honors the units of the inkscape document, so there shouldnt be any scale problems (i.e. mm vs inches - dont know about the transformation issues hinted at above). The other main change is that it will output information in layers, see the help for the effect for more details. Also, this has been set up with a framework so that we can add automation conversion from beziers to straight lines or arcs (to within machine tolerance). You can call this effect in two ways:
- 'Save As EMC GCode': This will create a single .nc file containing all the layer toolpaths.
- 'Effects|Export|Export as GCode': This will output one file per layer in a specified directory.
Here are the files:
GlenHarris?: OK, we now have the '2.0' version of Inkscape Gcode generation. The most important change is that it will now output some shapes (e.g. rounded rectangles) directly, and it can now export bezier curves. Bezier curves are linearly interpolated to machine resolution - a future extension would be to use arcs instead.
The code has been set up in a [repository] so that if anyone can contribute further changes they are welcome. To install, grab either the .zip or .tar.gz from here:
This file should be unzipped into your '/usr/share/inkscape/extensions' or 'C:/Program
? Files/Inkscape
?/Share
?/Extensions
?' directory. You can call this effect in two ways:
- 'Save As EMC GCode': This will create a single .nc file containing all the layer toolpaths.
- 'Effects|Export|Export as GCode': This will output one file per layer in a specified directory.
Make sure you read the help carefully because it will explain how to label layers etc.
Making Millimeters Default Units
And with these files the Inkscape makes nice G-code:
http://dp.jstenback.com/gcode/
Only issue is that the result is in inch, but with small modification in the
python script:
# 0.001 = inch, 0.2822222 = mm
xScale = self.options.scaleX * 0.2822222 # 8.5 / 744.1
yScale = self.options.scaleY * -0.2822222 #-11.0 / 1052.37
and:
# G20 = inch, G21 = mm
self.write("G21\nF%.4f\n" % feed)
the script makes nice G-code in mm.
[ courtesy of Péter Bocska on the emc-users mailing list ]