Introduction: Modifying Makercam G Code

This Instructable provides a Python program to post-process G code generated by Makercam.

ähöüokul's excellent instructable https://www.instructables.com/id/PCB-designing-an... describes how to to use a CNC machine to make PCB bards using only free software. The final step in the process is generating actual G code for drilling holes and isolation milling using Makercam.

I found that the generated .nc files have several problems:

  • There is no difference between repositioning and milling, meaning the moves are done with the same (slow) speed as the milling.
  • The coordinates are absolute, meaning your PCB has to be positioned at the origin and your controller has to allow negative Z values. My 3D printer/CNC machine uses RAMPS 1.4 running a stock Marlin controller and will not go below Z=0.
  • The tool remains at the end of the milling path.
  • Comments are given in parentheses instead of prefixed with ";". Marlin takes this, but returns annoying error messages.

The attached program, nc2gcode, treats any movement above the material surface as repositioning and by default moves the tool at 3000mm/min. Upward vertical moves (Z>0, no X or Y component) are also treated as moves. Downward vertical moves (Z<0) are broken into the above the material and within the material segments. The above material segment is treated as repositioning, while the within the material is treated as milling and the speed set by Makercam is left unchanged.

All the coordinates are converted to relative (G91). It assumes that the tool tip start position is at the material surface at the "logical origin," i.e., the left bottom corner of the work piece. After the job is finished, the tool returns to the starting position. The "safe height" set in Makercam is used for the final move back to origin.

The comments are prefixed with ";" to avoid error messages.

Note of caution: If you cancel the job generated with nc2gcode, your printer will remain in relative mode. Add "G90" to the script your software runs on job cancellation - this works nicely under OctoPrint, which I use to drive my printer.

To run the program, you need Python 2.7.*, though it may well work on earlier versions. It can be run via either

python nc2gcode [parameters]

or

nc2gcode [parameters]

if you made it executable and made sure the first line has the right location of your Python. I use it primarily on a Linux machine, but it also ran on my Mac. I would be surprised if it didn't run on Windows, but I don't have a box to try it on.

nc2gcode --help or nc2gcode -h gives usage

nc2gcode file.nc will generate file.gcode (input file needs .nc suffix for a single-argument invocation)

nc2gcode infile.nc outfile.gcode will make outfile.gcode from infile.nc. In two argument invocation, the file names can be arbitrary.

Use --f_move option to change the default repositioning feed rate from 3000mm/min to whatever you like.

I put no restrictions on this code - you are welcome to use, share or modify as you see fit. I hope you will find it useful.