Close
0%
0%

G Code Cleaner

Clean up your G-Code by filtering unnecessary points.

Similar projects worth following
If you have a G Code file with 50,000 lines of code?
Then perhaps some of those lines don't actually matter?
Here is a command-line utility to clean up the file.
---
Added a linux Mint version to the files download area.


G Code (gCode) Filter

I wrote this code as part of a laser engraver project to speed up the Grbl controller and Grbl interpreter (to stop them burning the work).

Most of the problem was with the original CAD design - far too many points.

The gCode file has 46,000 lines of code, even with a tolerance of 0.01 mm (the resolution of my laser engraver) the output is only 2000 lines of code (see the first image).

With a tolerance of 0.1 mm (very noticeable point reduction) the output is 1100 lines of code (see the second image).

Usage:

FilterGCode.exe -i Fish6.nc -o NewFish6.nc -t 0.01

Parameters:

-i Input file

-o Output file

-t Tolerance

Tolerance is the maximum distance the point (that if deleted) would be from the new line:

Code:

The code if written in plain C (using CodeBlocks) but uses Daniil Guitelson's BGI library.

You will need to add "graphics.h" and "libBGI.a" to your working directory, and the following linker options:

-lBGI -lgdi32

You will also need to add the working directory to your "compiler and linker search directories".

You can always delete the graphics code if you don't want it.

LIMITATIONS

Now a word of warning the code has limitations. It only passes the following codes:

G, X, Y, Z, F, S, T and M

I have only considered G0 and G1 in my code so you can try G2 or G3 but you will be disappointed. The code in not complicated so you can modify it if you like.

Regards AlanX

ezx_filter.c

Updated for ezx 2D library and new sscanf() behavour.

x-csrc - 8.38 kB - 12/09/2018 at 03:55

Download

ezxdisp-0.1.4.tar.gz

The new 2D graphics library.

gzip - 160.44 kB - 12/09/2018 at 03:53

Download

FilterGCode.run

A Linux Mint (X11) version

- 21.87 kB - 10/22/2017 at 08:40

Download

application/x-msdownload - 39.00 kB - 08/20/2016 at 12:46

Download

FilterGCode.exe

The Windows executable

x-msdownload - 38.00 kB - 07/27/2016 at 15:23

Download

View all 15 files

  • Update for new behavour of GCC 7.3.0

    agp.cooper12/09/2018 at 03:52 0 comments

    Update for GCC 7.3.0

    The latest gcc has changed. I have had to recompile Xbgi library (i.e. 2D graphics) and I found sscanf() works differently (i.e. 0X? is recognised as hexadecimal).

    I have opted to migrate from BGI (Windows) and Xbgi (linux), to ezxdisp.

    "ezx" is short and sweet and is available for Windows and Linux.

    The latest version is available at http://morihit.net/ezxdisp/

    Previously I used sscanf() as follows:

          for (j=0;Line[j];j++) Line[j]=toupper(Line[j]);
          tmp=strchr(Line,'G');
          if (tmp!=NULL) {
            sscanf((tmp+1),"%lf",&f1);
            if (f1<0) f1=0;
            block[i]->G=(long)f1;
          }

    It should read any number as a double which can be converted to long later.

    Now "G0X7.122" is read as G=7, X=0.0 but "G1X7122" still works fine.

    Now I have now coded:

          for (j=0;Line[j];j++) Line[j]=toupper(Line[j]);
          tmp=strchr(Line,'G');
          if (tmp!=NULL) {
            sscanf((tmp+1),"%ld",&d1);
            if (d1<0) d1=0;
            block[i]->G=d1;
          }

    AlanX

  • Feed Override

    agp.cooper08/20/2016 at 12:46 0 comments

      Override Feed Rates

      Added two options:

      1. -G0 FeedRate
      2. -G1 FeedRate

      These options override the file feed rates (i.e. deletes feed rates in the file and uses the option rate instead).

      Example:

      GCodeFilter.exe -i fish6.nc -o LaserFish6.nc -t 0.01 -l -g0 600 -g1 120

      This line (usually in a batch file) overrides both the G0 and the G1 feed rates. Also sets "laser" mode.

      AlanX

  • Laser G Code converter

    agp.cooper07/30/2016 at 04:01 0 comments

    Laser gCode

    It is a pretty simple exercise to convert milling G Code to laser G Code.

    Turn off the laser (M5) for G0 movements and turn on the laser (M3) for G1 (also G2 and G3) movements. May as well delete all the old M3, M5 and Z movements as they will be redundant.

    I will add a "-L" or -"l" to the command line options for "laser code".

    AlanX

View all 3 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates