Command line utility to 'clean' GCode

Thanks for your response. I own a miniature horizontal CNC mill and am a C# Visual Studio SQL programmer for a living. The programs the vendor provides with the mill have no comments.

After spending hours trying to memorize G-codes so I could understand their code, I was completely thrilled to find you efforts. I ran the vendor’s code through your program and finally was able to see what it was doing.

Paramount Die Company is very close to where I live and I want to talk to them about a part time programming job. http://www.paradie.com/
They use GibbsCam software and from their product line, it looks like they use lathes.

Here is the list of M Codes – CNC Milling and Lathe I was looking at:
Complete list of G and M codes which are common in almost all the cnc controls which are used in cnc machine workshops around the world.

Thanks,
Captain Jim Cummings

I don’t think the question is what the M codes are, but rather, what is it you
are thinking that the utility should do to these codes.

David Lang

If your utility could just display the Description that they have beside the codes, it would save the tremendous effort required to either memorize or look up each code as it it used.

Captain Jim

Hi Jim,

GCodeClean originally started life as a VS Code plugin, precisely so I could hover the mouse over any command and get it to tell me what it meant.

So yes, I still want it to be able to ‘transcribe’ some GCode with explanatory comments.

Thanks for that reference. I’ll compare those codes with the ones for RepRap 3D printers as well.

Ultimately I want to encapsulate all these codes and their ‘meaning’ so that GCodeClean can reliably manipulate any GCode file (within reason anyway).

Might be handy to put the gcode descriptions in an editable file (yes, I know source code is editable, but it’s a bigger project), at least for the non-RS274X codes added for 3D printers and controller vendor additions.

The code is already set up for me to add a command line option for this.
However, I need to expand the definition file so that command groups can be identified, as well as the priorities between commands, etc. And that requires dome refactoring.

OK - I’ve grabbed what I could from those tables and included in the tokenDefinitions.json file, which is where that stuff lives.

You should be able to git pull and rebuild the whole thing. Or just get the updated file and copy it over the existing one.

I still don’t have the associated ‘semantics’ for those commands to know how they should be grouped and prioritised, just the descriptions.

That looks excellent. Attached are my results. Thanks for your efforts.

ComplateCodeList-gcc.zip (1019 Bytes)

No problems, obviously if you have a reliable source for those other codes feel free to send me a reference, or put them into tokenDefinitions.json yourself and send me a pull request (you may need to do a fork to get github to accept it back)

Version 0.8.9.0 is up on GitHub

This is a minor bit of new functionality, cleaning up inappropriate use of G1 when the z-axis has a positive value and converting it to a G0.

Inspired by some proposed changes by a certain software vendor …

Did you get a chance to address the inappropriate use of G0 issue?

All my free time has gone into turning part of a 100 year old barn (where flat, level, and plumb were novel concepts) into a wood and Maslow shop, so CNC time has been non-existent. The swamprats have yet to express an opinion but no parts or have been disappearing. Need to leave them room for a nest in a corner just in case

If we’re talking about Fusion 360’s use of G1 everywhere, when it should use G0 when Z is +ve, then yes.

If you actually meant inappropriate use of G0, then please explain and I’ll see what I can do.

The problem with cutting move G1s changed into G0s posted in the dodgy thread

Thanks for reminding me - I’ll have to dig back into that thread to get back to the GCode file that was triggering the issue.

And now the inappropriate switching of G1 for G0 has been fixed, introducing …

Would it be possible to convert z-axis moves out of the work surface to G0 as well when no other axis is moving?

I’m all for that too, with an option to turn any upward Z move into a rapid. Estlcam, which our friend @Metalmaslow sells at a great price, does G0 retracts. Carbide Create, which does G1 retracts, has been my main weapon of choice lately and they’ve promised to open their post processor system which should sort this one out.

However we’re trying to lead md8n into producing a much needed gcode optimizer, which qualifies as scope creep. Next he’ll be encouraged to lump moves between rapids together and do a TSP solution on them (I’ve used optimizers that do this, with mixed results. Bounce all over gcode generators see a big benefit, ones that make even a modest attempt at decent travel moves don’t).

With luck I’ll be starting a base cabinet prototype today using the rebelted/realigned/rebladed older delta contractor saw in the expanded mooseshop, Hopefully the swamprats haven’t chewed up or removed a link from the belt. There will be extended width cabinets for corners, with a difficult to reach section for a swamprat hangout. It’s been an iterative process, each improvement contributes to the next one, after the obligatory half day trip to the hardware store or week long amazon prime “2 day” shipping cycle, of course.

you don’t want to change any upward move to g0, only ones where no other axis
are moving (think vcarve, lots of upward Z movement that is not rapid)

David Lang

This already happens. When the Z-Axis is set to a positive value, and there’s no other movement then it gets converted to a G0.