Command line utility to 'clean' GCode

Not working for me on W10 64 bit. All I get is a black popup window that flashes on my screen Am I missing something in the install?

Sorry for the very late reply. You are probably not missing anything. However you do need to run this application from the command line, so using a terminal of some kind.

If you’re on W10 I would recommend getting Windows Terminal from the Windows Store, and using that to run the app

are you just clicking on the program? I think you need to open a dos window and
run the toold from the command line.

has anyone done a video demo of this?

David Lang

Thanks for the help–and the quick replies
I was able to open the DOS window last night. Having difficulty loading my files (long file names in subdiectories with dates added). I will look into the Windows Terminal program.
May be using this quite often
Thanks again–really apprciate the help

md8n
Tried running CLI in the windows terminal window (now Powersell, I guess). Does not execute

PS C:\temp> .\cli.exe

gcodeclean --French Curve GRBL.nc

PS C:\temp> gcodeclean French Curve GRBL.nc
gcodeclean : The term ‘gcodeclean’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • gcodeclean French Curve GRBL.nc
  •   + CategoryInfo          : ObjectNotFound: (gcodeclean:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

Not sure what that all means. Tried running with gcode filename(above).
What am I missing?

try just running gcocdeclean, not the .\cli.exe

David Lang

Wherever you unzipped the gcodeclean-win-x64-standalone.zip file will be where the GCodeClean cli.exe is located.

If you’re unfamiliar with typing in folder paths at the command line then I’d recommend using File Explorer to copy the file you want to process to the same folder where cli.exe is.

Next you need to open up the Windows Terminal in this same folder. To do this in File Explorer;

  1. right mouse click on the folder name (in the left hand pane). This folder name will be different for you from what you see below.
  2. click on Open in Windows Terminal

image

With that Windows Terminal will open PowerShell in exactly the right folder.

At the PowerShell prompt you can now enter .\cli and GCodeClean’s CLI will run and display you the standard help text

md8n
Got it to run, I think, the --filename threw me. I thought it was asking for the filename
The g-code is truncated from 25KB to 1KB
When I run the output file in online NC viewer it appears as an empty file–there is nothing there
I apologize for the on-screen dump, but I thought you might see something that I’m missing
Here’s what I get:

PS C:\temp> .\cli --filename FrenchCurveGRBL.nc --annotate
Outputting to:FrenchCurveGRBL-gcc.nc
Clipping and general mathematical tolerance:0.0005
Arc simplification tolerance:0.0005
Z-axis clamping value (max traveling height):0
All tolerance and clamping values may be further adjusted to allow for inches vs. millimeters
Unhandled exception. System.IO.FileNotFoundException: Could not find file ‘C:\temp\FrenchCurveGRBL.nc’.
File name: ‘C:\temp\FrenchCurveGRBL.nc’
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at GCodeClean.IO.AsyncTextFile.ReadLinesAsync(String path)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\IO\AsyncTextFile.cs:line 19
at GCodeClean.IO.AsyncTextFile.ReadLinesAsync(String path)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Tokeniser.TokeniseToLine(IAsyncEnumerable1 lines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Tokeniser.cs:line 39 at GCodeClean.Processing.Tokeniser.TokeniseToLine(IAsyncEnumerable1 lines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Tokeniser.cs:line 39
at GCodeClean.Processing.Tokeniser.TokeniseToLine(IAsyncEnumerable1 lines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Dedup.DedupRepeatedTokens(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 34
at GCodeClean.Processing.Dedup.DedupRepeatedTokens(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 34 at GCodeClean.Processing.Dedup.DedupRepeatedTokens(IAsyncEnumerable1 tokenisedLines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Linter.SingleCommandPerLine(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Linter.cs:line 15 at GCodeClean.Processing.Linter.SingleCommandPerLine(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Linter.cs:line 15
at GCodeClean.Processing.Linter.SingleCommandPerLine(IAsyncEnumerable1 tokenisedLines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Processing.InjectPreamble(IAsyncEnumerable1 tokenisedLines, Context preamble, Decimal zClamp)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 20
at GCodeClean.Processing.Processing.InjectPreamble(IAsyncEnumerable1 tokenisedLines, Context preamble, Decimal zClamp)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 20 at GCodeClean.Processing.Processing.InjectPreamble(IAsyncEnumerable1 tokenisedLines, Context preamble, Decimal zClamp)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Processing.Augment(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 59 at GCodeClean.Processing.Processing.Augment(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 59
at GCodeClean.Processing.Processing.Augment(IAsyncEnumerable1 tokenisedLines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Processing.ZClamp(IAsyncEnumerable1 tokenisedLines, Context context, Decimal zClamp)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 165
at GCodeClean.Processing.Processing.ZClamp(IAsyncEnumerable1 tokenisedLines, Context context, Decimal zClamp)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 165 at GCodeClean.Processing.Processing.ZClamp(IAsyncEnumerable1 tokenisedLines, Context context, Decimal zClamp)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Processing.ConvertArcRadiusToCenter(IAsyncEnumerable1 tokenisedLines, Context context)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 264 at GCodeClean.Processing.Processing.ConvertArcRadiusToCenter(IAsyncEnumerable1 tokenisedLines, Context context)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 264
at GCodeClean.Processing.Processing.ConvertArcRadiusToCenter(IAsyncEnumerable1 tokenisedLines, Context context)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Dedup.DedupLine(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 15
at GCodeClean.Processing.Dedup.DedupLine(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 15 at GCodeClean.Processing.Dedup.DedupLine(IAsyncEnumerable1 tokenisedLines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Processing.SimplifyShortArcs(IAsyncEnumerable1 tokenisedLines, Context context, Decimal arcTolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 326 at GCodeClean.Processing.Processing.SimplifyShortArcs(IAsyncEnumerable1 tokenisedLines, Context context, Decimal arcTolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 326
at GCodeClean.Processing.Processing.SimplifyShortArcs(IAsyncEnumerable1 tokenisedLines, Context context, Decimal arcTolerance)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Dedup.DedupLinearToArc(IAsyncEnumerable1 tokenisedLines, Context context, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 193
at GCodeClean.Processing.Dedup.DedupLinearToArc(IAsyncEnumerable1 tokenisedLines, Context context, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 193 at GCodeClean.Processing.Dedup.DedupLinearToArc(IAsyncEnumerable1 tokenisedLines, Context context, Decimal tolerance)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Processing.Clip(IAsyncEnumerable1 tokenisedLines, Context context, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 401 at GCodeClean.Processing.Processing.Clip(IAsyncEnumerable1 tokenisedLines, Context context, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 401
at GCodeClean.Processing.Processing.Clip(IAsyncEnumerable1 tokenisedLines, Context context, Decimal tolerance)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Dedup.DedupRepeatedTokens(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 34
at GCodeClean.Processing.Dedup.DedupRepeatedTokens(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 34 at GCodeClean.Processing.Dedup.DedupRepeatedTokens(IAsyncEnumerable1 tokenisedLines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Dedup.DedupLine(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 15 at GCodeClean.Processing.Dedup.DedupLine(IAsyncEnumerable1 tokenisedLines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 15
at GCodeClean.Processing.Dedup.DedupLine(IAsyncEnumerable1 tokenisedLines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 52
at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 52 at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 52 at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 52
at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 52
at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 52 at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 52 at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 52
at GCodeClean.Processing.Dedup.DedupLinear(IAsyncEnumerable1 tokenisedLines, Decimal tolerance)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Dedup.DedupSelectTokens(IAsyncEnumerable1 tokenisedLines, List1 selectedTokens)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 464 at GCodeClean.Processing.Dedup.DedupSelectTokens(IAsyncEnumerable1 tokenisedLines, List1 selectedTokens)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Dedup.cs:line 464 at GCodeClean.Processing.Dedup.DedupSelectTokens(IAsyncEnumerable1 tokenisedLines, List1 selectedTokens)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.Processing.Processing.Annotate(IAsyncEnumerable1 tokenisedLines, JsonElement tokenDefinitions)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 463
at GCodeClean.Processing.Processing.Annotate(IAsyncEnumerable1 tokenisedLines, JsonElement tokenDefinitions)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Processing.cs:line 463 at GCodeClean.Processing.Processing.Annotate(IAsyncEnumerable1 tokenisedLines, JsonElement tokenDefinitions)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeClean.Processing.Tokeniser.JoinLines(IAsyncEnumerable1 tokenisedLines, String minimisationStrategy)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Tokeniser.cs:line 188 at GCodeClean.Processing.Tokeniser.JoinLines(IAsyncEnumerable1 tokenisedLines, String minimisationStrategy)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\Processing\Tokeniser.cs:line 188
at GCodeClean.Processing.Tokeniser.JoinLines(IAsyncEnumerable1 tokenisedLines, String minimisationStrategy)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\IO\AsyncTextFile.cs:line 36
at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\IO\AsyncTextFile.cs:line 36 at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\IO\AsyncTextFile.cs:line 36
at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+MoveNext() in D:\GitHub\GCodeClean\GCodeClean\IO\AsyncTextFile.cs:line 36 at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at GCodeCleanCLI.Program.RunAsync(Options options) in D:\GitHub\GCodeClean\CLI\Program.cs:line 149
at GCodeCleanCLI.Program.RunAsync(Options options)
at CommandLine.ParserResultExtensions.WithParsedAsync[T](ParserResult1 result, Func2 action)
at GCodeCleanCLI.Program.Main(String[] args) in D:\GitHub\GCodeClean\CLI\Program.cs:line 28
at GCodeCleanCLI.Program.(String[] args)

Here is the top of my French Curve in NC viewer (original gcode file) from Fusion.
I’m not sure why there is a variation between the simplified arcs on the left and the ones on the right

… and there is your answer

Unhandled exception. System.IO.FileNotFoundException: Could not find file ‘C:\temp\FrenchCurveGRBL.nc’.
File name: ‘C:\temp\FrenchCurveGRBL.nc’

It can’t find the file FrenchCurveGRBL.nc in the folder C:\temp. So the first thing for you to do is to copy that file to C:\Temp or you can enter the full path to that file in the --filename option

Thanks!
That file, (French Curve GRBL.nc) is in the same directory c:\temp as \cli
For some reason it states it wont read read that file with spaces or without but returns an empty file (1KB)
Am I missing something here? Duh

spaces in filenames are evil software tends to interpret it as two separate
filenames, not one.

try putting the entire filename in quotes

David Lang

So here’s what I found
W10 has this thing where it keeps write protecting my directories (may be a security setting)
I cant seem to override it just now
Unhandled exception. System.UnauthorizedAccessException: Access to the path ‘c:\temp-gcc.nc’ is denied.
Damn

This is saying that it is trying to access a file called temp-gcc.nc that is located in the root folder of c, i.e. c:\

So yeah, it won’t let you do that.

I suspect that the command you are entering is simply formatted incorrectly (spaces in wrong places, etc.)

Could you please run the following command at the PS C:\temp> prompt
dir frenchcurve*.*
And copy the results of that into a message.

Then if you could also copy the cli command you are using exactly as how you type it in.

md8n
I was able to process the file. I had to override the W10 directory write protection imposed by windows. I assume this is enacted to prevent ransomware attacks from .exe files

.\cli --filename French Curve GRBL.nc --minimise soft --annotate
Doesn’t appear to digest filename spaces–had to rename/remove spaces
PS C:\temp> .\cli --filename French.nc --minimise soft --annotate
Outputting to:French-gcc.nc
Clipping and general mathematical tolerance:0.0005
Arc simplification tolerance:0.0005
Z-axis clamping value (max traveling height):0
All tolerance and clamping values may be further adjusted to allow for inches vs. millimeters
1225
Exit code= 0


I click on the black box to override it, but windows keeps resetting it to Read-only. Every time there is an upgrades from windows the switch is reset to Read-only

So my next answer to that is to not use temp, considering that it is called temp its purpose is really as a temporary dumping ground for files being processed, not as a long term storage location. But history being what it is that’s what a lot of people used to use it for.

Instead create a folder for your projects, and stick them all in that, I’d also recommend creating subfolders for each individual project

md8n
Yes, I do have a folder where I keep my project work, with subdirectories (way too many). I used ‘temp’ to simplify adding all of the directory information to the file name. This is where gcodecleaner lives as well, for now

There’s a new GCodeClean :tada:

As usual go to Releases · md8n/GCodeClean (github.com) for the latest - it was supposed to be tagged as v0.9.4, but it ended up as v0.94 - doesn’t matter.

Anyway, what’s in it?

  • Upgraded from .net 5 to .net 6 The Fastest .NET Yet - released this week.
  • Motivated by that I finally got back to my Linear Deduplication improvements and got them working!
  • Which includes a new test just for Linear dedupe.
3 Likes

I think I downloaded the correct file for the gcode cleaner from github (im kind of new to this and get lost on that site) After extracting the zip file. When I execute the application file a dos box opens up and immediately closes. How do I get it to work? Using Windows 10. Thanks for your assistance.

-Tim