Mecode

From RepRap
Revision as of 14:38, 27 March 2014 by Jminardi (talk | contribs)
Jump to: navigation, search

Mecode is an open source library for generating GCode. It is written in python and licensed under the MIT license.

You can find the source code on github

Mecode is designed to simplify GCode generation. It is not a slicer, thus it can not convert CAD models to 3D printer ready code. It simply provides a convenient, human-readable layer just above GCode. If you often find yourself manually writing your own GCode, then mecode is for you. Mecode can generate basic GCode commands like line and arc, as well as composed commands like rectangles and meanders.

To use, simply instantiate the `G` object and use its methods to trace your desired tool path.

from mecode import G
g = G()
g.move(10, 10)  # move 10mm in x and 10mm in y
g.arc(x=10, y=5, radius=20, direction='CCW')  # counterclockwise arc with a radius of 5
g.meander(5, 10, spacing=1)  # trace a rectangle meander with 1mm spacing between passes
g.abs_move(x=1, y=1)  # move the tool head to position (1, 1)
g.home()  # move the tool head to the origin (0, 0)

By default mecode simply prints the generated GCode to stdout. If instead you want to generate a file, you can pass a filename and turn off the printing when instantiating the `G` object.

g = G(outfile='path/to/file.gcode', print_lines=False)
  • NOTE: `g.teardown()` must be called after all commands are executed if you are writing to a file.

The resulting toolpath can be visualized in 3D using the `mayavi` package with the `view()` method:

g = G()
g.meander(10, 10, 1)
g.view()

It is currently maintained by the Lewis Lab at Harvard University.