<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html><head><title>EMC Documentation Wiki: InkscapeHowto</title>

<meta name="KEYWORDS" content="Inkscape, Howto">
<link rel="stylesheet" href="emcinfo_files/template.css"></head><body>
<div class="wikiheader"><h1><a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?EmcKnowledgeBase"><img src="emcinfo_files/chips.gif" alt="[Home]" align="right" border="0"></a><a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?back=InkscapeHowto">InkscapeHowto</a></h1><a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?EmcKnowledgeBase" class="wikipagelink">EmcKnowledgeBase</a> | <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?RecentChanges" class="wikipagelink">RecentChanges</a> | <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=index">PageIndex</a> | <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=editprefs">Preferences</a> | <a href="http://www.linuxcnc.org/">LinuxCNC.org</a><br>
<form method="post" action="emcinfo.pl" enctype="application/x-www-form-urlencoded">
<br>Search: <input name="search" size="20" type="text"><input name="dosearch" value="1" type="hidden"><div></div>
</form><hr class="wikilineheader"></div><b>Difference (from prior author revision)</b>
(<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=browse&amp;diff=1&amp;id=InkscapeHowto">major diff</a>, <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=browse&amp;diff=2&amp;id=InkscapeHowto">minor diff</a>)<br> <br><strong>Added: 56a57,63</strong><br><table class="wikidiffnew" bgcolor="#cfffcf" width="95%"><tbody><tr><td>
 GlenHarris<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=GlenHarris" class="wikipageedit">?</a>:
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: <br> *'Save As EMC GCode': This will create a single .nc file containing all the layer toolpaths.<br> *'Effects|Export|Export as GCode':  This will output one file per layer in a specified directory.<br> Here are the files:<br> *<a href="http://wiki.linuxcnc.org/uploads/export_gcode.inx">upload:export_gcode.inx</a><br> *<a href="http://wiki.linuxcnc.org/uploads/export_gcode.py">upload:export_gcode.py</a><br> *<a href="http://wiki.linuxcnc.org/uploads/saveas_gcode.inx">upload:saveas_gcode.inx</a><br></td></tr></tbody></table>
 <br><strong>Added: 57a65,72</strong><br><table class="wikidiffnew" bgcolor="#cfffcf" width="95%"><tbody><tr><td>
 GlenHarris<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=GlenHarris" class="wikipageedit">?</a>:
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.<br> <br> The code has been set up in a <a href="http://bitbucket.org/jst/inkscape-gcode/">[repository]</a> so that if anyone can contribute further changes they are welcome.  To install, grab either the .zip or .tar.gz from here:<br> *<a href="http://bitbucket.org/jst/inkscape-gcode/src/tip/dist/">[Bitbucket inkscape-gcode dist tip]</a><br> This file should be unzipped into your '/usr/share/inkscape/extensions' or 'C:/Program<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=InkscapeHowto/Program" class="wikipageedit">?</a> Files/Inkscape<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=InkscapeHowto/Inkscape" class="wikipageedit">?</a>/Share<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=InkscapeHowto/Share" class="wikipageedit">?</a>/Extensions<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=InkscapeHowto/Extensions" class="wikipageedit">?</a>' directory.  You can call this effect in two ways: <br> *'Save As EMC GCode': This will create a single .nc file containing all the layer toolpaths.<br> *'Effects|Export|Export as GCode':  This will output one file per layer in a specified directory.<br> Make sure you read the help carefully because it will explain how to label layers etc.<br></td></tr></tbody></table>
<hr class="wikilinediff">
<div class="wikitext">This page describes an "easy" way to convert Inkscape paths to gcode files.
<ul>
<li>Inkscape is a 2D drawing program that can be used for drafting
</li><li>Paths are the drawing elements.
</li><li>Inkscape can manipulate bitmaps, fonts and objects, all of which can be converted to paths.
</li></ul>
<h2>Setup of Inkscape (and gcode scripts) on Ubuntu</h2>

<ul>
<li> From Ubuntu 6.06's package manager, install Inkscape 0.43
</li><li> With root priviledges, copy the following files 
<ul>
<li><a href="http://wiki.linuxcnc.org/uploads/gcode.inx">upload:gcode.inx</a>
</li><li><a href="http://wiki.linuxcnc.org/uploads/gcode.py">upload:gcode.py</a> 
</li></ul>
</li></ul>
to your /usr/share/inkscape/extensions directory. Rename those files to gcode.inx and gcode.py.
<ul>
<li> Enable effects: In Inkscape, open the preference page (SHIFT+CTRL+P), select the misc tab and check "Enable script effects". 
</li></ul>
<p>
</p><dl>
<dt></dt><dd><a href="http://wiki.linuxcnc.org/uploads/inkscapeprefs.png"><img src="emcinfo_files/inkscapeprefs.png" alt="upload:inkscapeprefs.png"></a>
</dd></dl><ul>
<li>Restart Inkscape, you should now see a "Effects" menu with a "Export as GCODE" entry
</li></ul>
<p>
</p><h2>How it works</h2>

<ul>
<li> The idea is that the "Effect" will generate a gcode file (inch mode) for the SELECTED PATHS
<ul>
<li> SELECTED: if nothing is selected, you get a useless gcode file
</li><li> 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.
</li><li> Styles, strokes, color and other properties are ignored.
</li></ul>
</li><li> Paths are converted to straight lines using G01 codes.
<ul>
<li> This seems is perhaps a huge limitation
</li><li> One reason is that the author is very lazy, 
</li><li> He doesn't understand Bezier maths and control points
</li><li> There are too many tunable parameters (how many segments to use, etc)
</li><li> He found out that Inkscape has great tools to add/remove nodes.
</li></ul>
</li></ul>
<p>
</p><h2>Tutorial</h2>

<ul>
<li>Draw a shape (or object, text etc... but don't forget to convert to shape) ... like this:
</li></ul>
<a href="http://wiki.linuxcnc.org/uploads/inkscapeshape.png"><img src="emcinfo_files/inkscapeshape.png" alt="upload:inkscapeshape.png"></a>
<ul>
<li>Don't use the "Export as GCODE" effect just yet, or you'll get a result like that:
</li></ul>
<a href="http://wiki.linuxcnc.org/uploads/inkscapebadngc.png"><img src="emcinfo_files/inkscapebadngc.png" alt="upload:inkscapebadngc.png"></a>
<ul>
<li>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.
</li></ul>
<a href="http://wiki.linuxcnc.org/uploads/inkscapebestshape.png"><img src="emcinfo_files/inkscapebestshape.png" alt="upload:inkscapebestshape.png"></a>
<ul>
<li>Select the "Export as GCODE" effect from the "Effect" menu, and go wild on the effects parameters.
</li></ul>
<a href="http://wiki.linuxcnc.org/uploads/inkscapegcodeeffect.png"><img src="emcinfo_files/inkscapegcodeeffect.png" alt="upload:inkscapegcodeeffect.png"></a>
<ul>
<li>Voila, an easy way to go from vector to EMC. 
</li></ul>
<a href="http://wiki.linuxcnc.org/uploads/inkscapegoodngc.png"><img src="emcinfo_files/inkscapegoodngc.png" alt="upload:inkscapegoodngc.png"></a>
<p>
</p><p>
</p><h2>Feedback</h2>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.
<ul>
<li> Pros
<ul>
<li> The paths would be kept simple in the svg file, because node count could be limited.
</li><li> The GCODE would "look" better, and SVG files would not
require editing. This is good for clipart, where the author is not the
machinist.
</li><li> SVG paths are supposed to be "curvy". Using them as straight segments is an ugly hack.
<ul>
<li> 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. ;)
</li><li> i double dog disagree. any curve interpolation should use <a href="http://axis.unpythonic.net/01171767993">[biarcs]</a>
- 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.
</li></ul>
</li></ul>
</li><li> Cons
<ul>
<li> 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
euristics to decide the 'straightness' of a segment based on its length
and control points).
</li><li> 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).
</li><li> 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.
</li><li> 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.
<ul>
<li>I have patched <a href="http://fabrizio.zellini.org/wp-content/uploads/2008/02/gcode.py">[gcode.py]</a> and <a href="http://fabrizio.zellini.org/wp-content/uploads/2008/02/gcode.inx">[gcode.inx]</a>
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.
</li></ul>
</li></ul>
</li></ul>
Perhaps the best approach is some kind of middle ground.
<p>
GlenHarris<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=GlenHarris" class="wikipageedit">?</a>:
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: </p><ul>
<li>'Save As EMC GCode': This will create a single .nc file containing all the layer toolpaths.
</li><li>'Effects|Export|Export as GCode':  This will output one file per layer in a specified directory.
</li></ul>
Here are the files:
<ul>
<li><a href="http://wiki.linuxcnc.org/uploads/export_gcode.inx">upload:export_gcode.inx</a>
</li><li><a href="http://wiki.linuxcnc.org/uploads/export_gcode.py">upload:export_gcode.py</a>
</li><li><a href="http://wiki.linuxcnc.org/uploads/saveas_gcode.inx">upload:saveas_gcode.inx</a>
</li></ul>
<p>
GlenHarris<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=GlenHarris" class="wikipageedit">?</a>:
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.
</p><p>
The code has been set up in a <a href="http://bitbucket.org/jst/inkscape-gcode/">[repository]</a> so that if anyone can contribute further changes they are welcome.  To install, grab either the .zip or .tar.gz from here:
</p><ul>
<li><a href="http://bitbucket.org/jst/inkscape-gcode/src/tip/dist/">[Bitbucket inkscape-gcode dist tip]</a>
</li></ul>
This file should be unzipped into your '/usr/share/inkscape/extensions' or 'C:/Program<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=InkscapeHowto/Program" class="wikipageedit">?</a> Files/Inkscape<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=InkscapeHowto/Inkscape" class="wikipageedit">?</a>/Share<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=InkscapeHowto/Share" class="wikipageedit">?</a>/Extensions<a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=edit&amp;id=InkscapeHowto/Extensions" class="wikipageedit">?</a>' directory.  You can call this effect in two ways: 
<ul>
<li>'Save As EMC GCode': This will create a single .nc file containing all the layer toolpaths.
</li><li>'Effects|Export|Export as GCode':  This will output one file per layer in a specified directory.
</li></ul>
Make sure you read the help carefully because it will explain how to label layers etc.
</div><hr class="wikilinefooter">
<div class="wikifooter"><a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?EmcKnowledgeBase" class="wikipagelink">EmcKnowledgeBase</a> | <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?RecentChanges" class="wikipagelink">RecentChanges</a> | <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=index">PageIndex</a> | <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=editprefs">Preferences</a> | <a href="http://www.linuxcnc.org/">LinuxCNC.org</a><br>
This page is read-only.  Follow the <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?BasicSteps" class="wikipagelink">BasicSteps</a> to edit pages. | <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=history&amp;id=InkscapeHowto">View other revisions</a><br>Last edited March 16, 2009 1:11 pm by <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Glenharris" title="ID 11663 from 125-238-39-84.broadband-telecom.global-gateway.net.nz">Glenharris</a> <a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?action=browse&amp;diff=1&amp;id=InkscapeHowto">(diff)</a>Published under a Creative Commons License<br></div></body></html>
