Hey! This thing is still a Work in Progress. Files, instructions, and other stuff might change!

Unicorn G-Code Extension for Inkscape

by schmarty, published

Unicorn G-Code Extension for Inkscape by schmarty Feb 1, 2011



Unicorn G-Code Extension for Inkscape by schmarty is licensed under the GNU - GPL license.

Use This Project

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag


Thing Statistics

32962Views 5701Downloads Found in Art Tools


One problem that has often plagued users of the MakerBot Unicorn[1] is the long and confusing chain of tools required to go from a nice vector drawing to a G-Code file that can be plotted from ReplicatorG.

mifga did an awesome tutorial[2] that made it possible to understand the steps needed to work all of these tools, but it was obvious that something better was needed.

So, I made a mashup of scribbles.py[3] and the Egg-Bot Driver for Inkscape[4] to bring you the inkscape-unicorn extension for Inkscape!

Once installed, this extension allows you to save files in "MakerBot Unicorn G-Code (*.gcode)" format!

Learn more, download, and contribute at the GitHub page for this project:


If you're desperate, you can also download the zip file attached to this thing, but it is guaranteed to be out of date. Please get the latest version from GitHub. :)

Thanks to langfordw for the original Unicorn Logo[5] used as an example on this Thing.


I'm updating and adding features to this script as my first days for the February Thing-A-Day. Updates below:

[1] Unicorn - http://store.makerbot.com/makerbot-unicorn-pen-plotter-kit.html
[2] mifga's Unicorn Tutorial - http://wiki.makerbot.com/unicorn-tutorial-01
[3] scribbles.py - https://github.com/makerbot/Makerbot/tree/master/Unicorn/Scribbles%20Scripts
[4] Egg-Bot Driver for Inkscape - http://code.google.com/p/eggbotcode/
[5] Unicorn Logo by langfordw http://www.thingiverse.com/thing:4197


From the README:


Copy the contents of src/ to your Inkscape extensions/ folder.

Typical locations include:

* OS X - /Applications/Inkscape.app/Contents/Resources/extensions
* Linux - /usr/share/inkscape/extensions
* Windows - C:\Program Files\Inkscape\share\extensions


* Size and locate your image appropriately:
** The CupCake CNC build platform size is 100mm x 100mm.
** Setting units to mm in Inkscape makes it easy to size your drawing.
** The extension will automatically attempt to center everything.

* Convert all text to paths:
** Select all text objects.
** Choose Path | Object to Path.

* Save as G-Code:
** File | Save a Copy.
** Select MakerBot Unicorn G-Code (*.gcode).
** Save your file.

* Preview
** For OS X, Pleasant3D is great for this.
** For other operating systems... I don't know!

* Print!
** Open your .gcode file in ReplicatorG
** Set up your Unicorn and pen.
** Center your build platform.
** Click the Build button!

More from Art Tools

view more

All Apps

Upgrade this Thing with Thingiverse Apps

Tools and Utilities

Repair, slice, or enhance this Thing

Auto-magically prepare your 3D models for 3D printing. A cloud based 3D models Preparing and Healing solution for 3D Printing, MakePrintable provides features for model repairing, wall thickness...

App Info Launch App

hello sir,
your extension is very good but it doesn't help me to save in g code. there is a error reporting that ".....not saved". what can i do then to save my g code files from inkscape to my laptop.?

Nov 28, 2016 - Modified Nov 28, 2016
schmarty - in reply to lagariscience

Hi lagariscience,

Sorry to hear that you are having trouble. Please make sure that you are using the latest version of this extension, which can be found on GitHub:


If you are still having trouble, please open an issue on GitHub.


Hi, love your program, so easy to use. I'm using it for a cnc machine and am having problems with the way it automatically centers itself, ignoring the original page sizing. Half of each image ends up with negative X and Y co-ordinates. Can you tell me what I need to change in the code so it's laid out to the document?

Glad you are getting use out of it!

The plugin is currently hard-coded to center the drawing and ignore the document coordinates. It assumes that the "home" of your work area (X=0, Y=0) is at the center of the machine's work area.

There is a feature for setting the X and Y home coordinates for the resulting G-Code. In the "Homing" tab you can use this to offset the "home" coordinates relative to your machine's home coordinates. E.g. if the center of your work area is X=50, Y=75, you should be able to set your home to X=-50 Y=-75, which will offset the entire resulting G-Code.

The home coordinate offset handling is in the initializer for the SvgParser, here: https://github.com/martymcguire/inkscape-unicorn/blob/master/src/unicorn/svg_parser.py#L228

Hope that helps!

Sep 21, 2016 - Modified Sep 21, 2016
seanenroute - in reply to schmarty

Thanks. I tweaked the code in SvgParser to:

def parse(self):

0.28222 scale determined by comparing pixels-per-mm in a default Inkscape file.

 self.svgWidth = self.getLength('width', 354) * 0.28222
 self.svgHeight = self.getLength('height', 354) * 0.28222
 self.recursivelyTraverseSvg(self.svg, [[0.28222, 0.0, 0.0], [0.0, -0.28222, (self.svgHeight/1.0)]])

#TODO: center this thing
def recursivelyTraverseSvg(self, nodeList, 
                         matCurrent = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]],
                         parent_visibility = 'visible'):

It seems to be working for me. Feel free to tweak some more if you see an error.

Also I switched up the pen up and down code to use the M280 servo command:

self.codes.append("M280 P0 S%0.2F (pen up)" % self.pen_up_angle)
self.codes.append("M280 P0 S%0.2F (pen down)" % self.pen_down_angle)

Mostly I'm posting this in case someone else comes along with the same issues.

Side note, I don't know why the comment formatting is freaking out.

can you help me about this script, what happen about this
Traceback (most recent call last):
File "unicorn.py", line 23, in
from unicorn.context import GCodeContext
File "D:\inkspace\inkscape\share\extensions\unicorn.py", line 23, in
from unicorn.context import GCodeContext
ImportError: No module named context

I always get this message after trying to save as gcode,
"Traceback (most recent call last):
File "unicorn.py", line 78, in
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex.py", line 268, in affect
File "unicorn.py", line 72, in effect
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/unicorn/svg_parser.py", line 223, in parse
self.svgWidth = self.getLength('width', 354) 0.28222
TypeError: unsupported operand type(s) for
: 'NoneType' and 'float'"

I'm brand new to Inkscape so I may be missing something obvious.

For those of you just now trying this...

Go to File -> Document Properties
Under "Custom Size" change the units to pixels.

Now try to save your svg as gcode. It worked for me. Leaving the units as "mm" did not work and returned the same error. Schmarty and jsc explained this, but I just wanted to make it clear for those who didn't follow the whole conversation that happened a long time ago over several months. Easter is coming and we all need to get our SphereBots working!

Thank you Man! This error was frustrating me. Great answer. Yes it did work for me too. :-)

There is a workaround for this problem, which appears to happen when a document has no unit of measurement set.

In your document settings, make sure that your SVG has some kind of units. I have read reports saying that mm or px work.

Hope that helps!

Had the same problem. It appears that the plugin only handles pixels. From the comments to "getLength()":
Get the attribute with name "name" and default value "default"
Parse the attribute into a value and associated units. Then, accept
no units (''), units of pixels ('px'), and units of percentage ('%').

So, in document properties, set your units to pixels.

It looks like the Inkscape extensions API has changed with the latest version of Inkscape. I haven't had a chance to dig in and figure out the new API, yet, but I hope to have a fix in the coming days.

I have still this Problem, is there an solution or fix?

I have posted a workaround above that should help.

Oh, thanks. I thought it was just me! I would offer to help, but I got no skills :-)

I am trying to use this on a replicator clone and replacing the M300 S30.00 with M126 (laser on) and M300 S50.00 with M127 (laser off) and adding the G4 P0. But when I go to print it tries to go to the extremes of my build plate and the laser never comes on. Anyone else ran into this?

Comments deleted.

I put the unicorn folder, .gitignore, unicorn.inx, unicorn.py in my windows extension folder but it wont run.

could you help me?

Hi hyppyayo,

Sorry if the instructions are a bit confusing. In addition to putting the unicorn.inx and unicorn.py files into your Inkscape extensions folder, you also need to copy over the whole src/unicorn/ subfolder with the init.py, context.py, entities.py, and svg_parser.py files. These should go into a subfolder of your extensions folder called unicorn.

I hope that helps!

Nothing to do, My Inkscape did not recognize the extension. Probably is my Inkscape version, i gor problem also with Laser-Engraver extension.

What kind of Inkscape version do you have?

I'm running Inkscape for OS X v0.48. I haven't updated this extension in a while so it's possible that the code needs to be changed for the newer version(s) of Inkscape?

Im using the last inkscape version with windows8.1, i'll try to downgrade to 0.48. Extension must be installed like for OSX?

Jan 10, 2015 - Modified Jan 10, 2015
hyppyayo - in reply to hyppyayo

tried to install inkscape 0.48.0 and many other versions and put into extension folder unicorn.inx, unicorn.py , also in extension folder the folder called UNICORN (within init.py, context.py, entities.py, and svg_parser.py files) but inkscape did not recognize the extension, in the extension tab there is no Unicorn ext.
Could you help me? i'd like to use this extension with my rep2x with laser engraver mod

Ah, I think I may have found the problem. You may want to check out the slightly better instructions on the GitHub page for this extension: https://github.com/martymcguire/inkscape-unicorn

The extension doesn't actually show up in the extensions menu because it's an "Export" plugin. This means it should show up in the list of file formats when you try to "Save As".

thanks Schmarty, i found the plugin! Now i'm trying to make it work with laser.

Any luck with the laser? I am also attempting to make it work with laser. Does this use M126/127 codes?.

yes, now I can use the laser very well.

How did you pull it off? I am still not able to get unicorn to work, just the JTech plugin.

First off Let me say Thank you. Second, I have added a laser engraver to my FlashForge Creator Pro and am trying to get 2d plotting / engraving to work reliably. I have had the best results yet using this plugin. However, I am still having issues with the laser not turning off on travel move. I am replacing M300 S30.00 with M126 (laser on) and M300 S50.00 with M127 (laser off) Even if those are the only changes i make I still have issues with the laser being on during travel moves. I have even tried using your supplied .gcode and making my replacements. Any suggestions?

Hi discojon,

It's exciting that you are making progress using this extension to power a laser engraver! Let's see if I can help.

My first question (and it's a bit obvious, sorry), is to double check your M-Codes for laser on and off to make sure they are correct. You might want to try making some hand-written G-Code files to test this out.

Second - is it possible that the laser has a response time delay to being turned on and off? If so, you might want to add some "dwell" commands (G4?) to have the machine pause after disabling or enabling the laser.

If you are still having trouble, feel free to contact me through my profile page. That way we can swap email addresses and continue the conversation.

I sent you an email.

The solution was G4 P0. The laser was over running the carriage. Including G4 P0 before the laser on (M126) and laser off (M127) solves my issue.

hi discojon, i'm tring to use laser too, my question is... how could i add all G4 P0 line in the gcode file?

i've to write one by one? or there is a way to add the line in 1 step only?

Jan 12, 2015 - Modified Jan 12, 2015
discojon - in reply to hyppyayo

I generate the gcode using this plugin, then open the file in a word processor and use find and replace. Be sure you set the pen up and pen down delays to different times so you can search and replace each command separately. I replace the first pen down command with G4 P0, the following Dwell (G4 Pxxx) with M126 (laser on), the next Pen up with G4 P0, and lastly, final dwell with M127 (laser off). Make sense?

Anyone use this lately? I keep getting this error trying to save an svg to use on my new spherebot / eggbot:

Traceback (most recent call last):

File "http://unicorn.pyunicorn.py", line 108, in <module>


File "/Applications/Inkscape.app/Contents/Resources/extensions/http://inkex.pyinkex.py", line 215, in affect


File "http://unicorn.pyunicorn.py", line 104, in effect


File "/Applications/Inkscape.app/Contents/Resources/extensions/unicorn/http://entities.pyentities.py", line 77, in get_gcode

for points in self.segments:

AttributeError: SvgPath instance has no attribute 'segments'</module>

hello, you have solved the problem???

I haven't used this in a bit, but I have seen similar errors in the past.

The plugin is pretty sensitive to weird paths. Open up the XML editor in Inkscape (Ctrl-Shift-x) and check your SVG's XML to look for empty paths. These show up as <svg:path> elements with a missing or empty "d" attribute. If you find any, delete them.

This plugin was written for the Cupcake's cartesian coordinates and platform size. This probably won't map super well onto a sphere, which work on rotational coordinates and has different extents for each motor.

If you're driving it with an EiBotBoard, you would probably have better luck using the EggBot driver/plugin for Inkscape, instead. :)

Cool! Thanks! replaced M300 commands with G1 Z0 commands to run on my Prusa Mendel

Sorry if this is a stupid question, what firmware are you using? Does it only work with makerware?

This was written for the Cupcake CNC + Replicator G. It generates G-Code, so it should work with any bot that can speak G-Code, provided that you update the pen-up/pen-down commands to ones that your machine understands.

Thanks for making this. I very slightly modified the code to do z moves for the pen up/down and it worked out great.

TheCuber - in reply to

Hey i know this was along time ago, but how were you able to use the Z axis to control pen up and down? I kinda want to try this out. Any help would greatly be appreciated.

Hey! Glad you want to check it out!

Take a look at my comment about http://context.pycontext.py from a few weeks ago. It should get you pointed in the right direction.

Really impressed, thanks for making the G-Code extension. I'm making a Spherebot and this really makes it work! Keep up the great work!

I can't activate unicorn, what's my faught?

Can you add a travel speed option? I've been using this script with my laser unicorn - etch speeds are around 200 - 400 mm/min... I'd love to have it move much faster when not etching.

That's a good idea. I'll add it to the issues list on GitHub for when I next get around to working on it.

If you'd like to make the change yourself, it should be pretty straightforward to hack it into the Python scripts.

Where is the ''Love it'' button? This thing is so awesome. I hated dealing with the python scribbles script. Great job. I have it installed and in use. You should really consider posting a page on the reprap wiki and Makerbot wiki because it is really a huge leap forward on user friendliness. I am very surprised this thing hasn't gotten more attenion. Anyways the thing is awesome! :)

Thanks! mifga and I are planning to write up some new tutorials when we get a chance. I am really excited to see what people come up with using this!

What needs to change so I can use a stock cupcake as a drawbot and this script? The Z just needs to hop up 2mm.

did you found out how to change this? im a total mess in writing code, (but i can make computer drawings)

The Python script in unicorn/http://context.pycontext.py is the thing to edit. There are several lines that read something like:

self.codes.append("M300 S%0.2F (pen up)" % self.pen_up_angle)

And for pen down:

self.codes.append("M300 S%0.2F (pen down)" % self.pen_down_angle)

The "M300" is an M-Code telling the machine to lift the servo for the Unicorn (more info here: http://replicat.org/mcodeshttp://replicat.org/mcodes )

You should be able to replace all of those lines with some reasonable Z moves. For example, if you always start your drawings with the pen 20mm above your drawing surface, you could change all pen up commands to:

self.codes.append("G0 Z20 (pen up)")

And pen down would be:

self.codes.append("G0 Z0 (pen down)")

It's a lot of string replacement (bad code design, my bad!) but it is pretty straightforward.

As I said earlier, you have to be careful not to smush things. The Unicorn toolhead has a lot of "give", allowing the pen to slide up and down. The Z-axis has no such "give" and will happily crush a pen tip.

A good question! You'd need to change the code of the extension itself to turn all pen-up and pen-down commands into Z-axis moves. Shouldn't be too challenging.

Try not to smash/smush anything, though. :)

I couldn't agree more : Today I grabbed four Inkscape svg files that were the source for existing Unicorn plottables at Thingiverse and ran them to gcode with practically no issues. Even the stepping on curves wasn't as noticeable as when you run a big circle. And now that Matt Mets has fixed the G3 issue in ReplicatorG, there is a lot of room to tune this tool up to take over ye olde long process of generating Unicorn gcode. Also, I ran an XKCD webcomic for fun, and within 30 seconds had a unicorn printing, well, what appears to me to be a Klingon language variant. Text still needs some work. (not with the script, with the tools to trace usefully into Inkscape for paths for printing!) Marty -- go for the Hershey font trickery we discussed!

SO SO SO awesome!!!