Blender 2.5 gcode reader

by zignig, published

Blender 2.5 gcode reader by zignig Feb 4, 2011



Blender 2.5 gcode reader by zignig is licensed under the GNU - LGPL license.

Liked By

View All

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

7789Views 1667Downloads


This has been superseded by http://www.thingiverse.com/thing:6236

This is a python3 script for blender 2.5 that reads gcode files and creates polylines for tool head moves. It also animates with 1 frame per layer.

Put the script up on github for development



  1. open text file in blender2.5
  2. edit the file path
  3. run script ( alt P )
  4. visualize gcode

All Apps

Upgrade this Thing with Thingiverse Apps

No results.

I have an idea I would like to try, but it it requires me to know the predicted geometry of material laid down at a number of intervals mid print. Would this plugin be able to give me such information? If so, would it be possible to convert that geometry into a boolean mask in cartesian coordinates that simply indicates wheteher plastic exists at a given set of coordinates?

This is awesome. Unfortunately it does not when it has the M codes (101 103 108) removed.

Is it possible that you can make it work without them? Then a stepper extrurder user would be able to use it too. (I have a mendel-parts reprap....)

Still: its awesome.... Thank you for the effort.

I am doing it at the moment the way that I put a M101 command in the beginning and an M103 command to the end of the gcode file...


I just got my machine and have been printing my own models for a week.
The only thing that i felt was missing was "a python script for showing all the layers in blender" and it was really a case of doing it myself, or being paitent enough for someone else do to it..
8 hours later, and its right t

This is the best forum ever.

Tomorrow, I'm going to wish for someone who can take the model produced here and convert it back into gcode. Then we can can start making slight modifications and start picking where the "stringers" will form when the extruder hops over the gaps.

It'd be extra cool if this (or v2 or v3 of this) read
amp; parsed comments. In particular, the numbers following "(
gt;" and "(
gt;" would be good to parse, if present.

You could also figure out thread height from the gcode - good for files that don't have comments or don't come from skeinforge - but the widths are tricky. Skeinforge may write the perimeter width to the file as a comment but it doesn't appear to include the infill width or things like differences
in the shape of bridge layers due to the feed/flow modifiers..

Hi sorry too ask but i know nothing about blender ( i use 3DS Max) and how it works could you please post an idiot guide to running this script.


Bye the way this is awsome.....

you r genious!

now do it for cinema4D XD

ok, how do I remove comments from the gcode so it will work? It appears to work fine for the gcode provided, but doesnt seem to work for commented gcode. THANKS FOR THIS!!!

im on linux, so i lazily did it in vi with regex

  1. get a text editor that does regex

  2. (vi only) use 'dd' to drop the first lines that look like comments

  3. :%s/(.*//g
    this will drop all other comments from the file

  4. :%s/;//g
    this drops all the semi-columns

  5. :g/^$/ d
    this drops all the blank lines

  6. last there are two lines that look like this:
    G162 Z F500 (home Z axis
    G161 X Y F2500 (home XY axes minimum)
    you can drop them too.

no doubt the code will be updated very soon to fix all this.

As others have said, run blender from console for clues. When it works, blender freeses for a few mins while it processes. If it failed, you get window control back i

and, if you have perl

run this script and
gt; it to a file.


open FILE, $ARGV[0] or die $!;

while (
gt;) {





if (!m/^\s+$/) {

     print $_;



Ok, the answer is to turn off comments in the export module in skeinforge. You may also have to manually delete you start.txt and the beginning of the file? For me, if I could get rid of that, then it seems to work.

I'm very excited -- and Robot Hospital! wants to feature a quick demo of this in the next couple of weeks. Email me at griffin at makerbot dot com so we can chat!

Wow - this is really great!


I messed with this a bit and it is awesome!! I posted a render of my favorite object.

I got the comments removed so gcode from skeinforge goes right in. Can I send it to you? Then you can update it here!!

Or i can set it up on my github account if you don't mind.

Tested on my 2.5 machine, works great! Wonderful!

Blender 2.5's new interface has some tricks for creating toolshelf widgets that do things like select constants and (presumably) file selection boxes. If I get a chance I'll give building that part a try because this would be a fabulous add-on then.

Heck, it's already going to make my life a lot

You sir are a certifiable genius.

As Blender user I love this !

MaskedRetriever : +1 !

This is very exciting! A really beautiful alternative to Skeinview, etc on machines not compatible with Pleasant3D. Also, it's wonderful that scripting in Blender is getting applied to 3D printing, because ultimately Blender should totally have "3D printer drivers" that hook directly to the printer and print from Blender.

Because that will be badass.


If you run blender from a terminal , you should get some info.
At the moment it does not deal with (bracketed) comments in file.

I does not require any other packages , I am running on Blender 2.56a on Ubuntu 10.04.

I should put the script up on github , so it can be shared better :)

Ok well this is the output

opening /home/b/test.gcode
19669 lines
no code ;
building curves
has 0 layers
createing poly lines
profile exisits
animating build
frame 0
finishing parsing

I've tried it with code generated by replicatorG and repsnapper. I've also tried an assortment of items from a simple cube to complex items.

What window should the output be in 3Dview or UVImage editor or ?

Ah , I have only really tested it on the gcode files I had at hand,

so to fix your problem... ( and many of these )

if you remove the 'break' on line 286 , it won't just stop when it gets a bad code. :)

The last break seems to appear @ line283 and when I remove it I get this

from gcode created by replicatorG

opening /home/b/test2.gcode
1444 lines
no code (
no code (
Traceback (most recent call last):
File "http://gcode.pygcode.py", line 287, in


File "http://gcode.pygcode.py", line 264, in process

val = float(j[1:])

ValueError: could not convert string to float: TW)

lt;unknown location

lt;unknown location

And this from gcode created by Repsnapper

opening /home/b/test.gcode
19669 lines
no code ;
T0 ;select new extruder
bad com 0
building curves
has 0 layers
createing poly lines
profile exisits
animating build
frame 0
finishing parsing

Could you upload a sample gcode
file for testing?

I think I got this working by adding..

'18' : undef,

...around like 78 and doing a copy/paste of the ignore comments block at 261 to also ignore things that start with a ( char. That and commenting out the last break.

It seems unhappy with G, M or T gcode lines that it doesn't know. I'd think the thing to do here would be to just ign
ore ones it doesn't know instead of trying to know all of them - I'd do this but python is PFM to me..

added the gcode that I have used , need to sort out comment processsing...

Your Gcode works perfectly.

I have tried removing all the comments from my Gcode created by ReplicatorG and/or Repsnapper and they still fail to produce anything.

Just thought I would add that my blender is 2.56 r34630 on Ubuntu 10.10

This has the possibility of being very, very pretty.