Command line utility to 'clean' GCode

I got this fixed in the latest release.
I’ve also added a specific test for it in the unit tests.

1 Like

v0.9.0 has been released:
Release Migrate to .Net 5 · md8n/GCodeClean (github.com)

This includes a fix for the bug that @mooselake found.

I’ve been adding more unit tests as well. Including a test for the bug that Kirk found of course.

2 Likes

Hate to be so dense but when I run the latest GCodeClean-master.zip, it only goes as far (Preamble completed by GCodeClean) Please advise. Thanks

OK - I just tried extracting from gcodeclean-win-x64-standalone.zip (github.com)
and then ran a file through that without dramas.

There could be something ‘interesting’ in your file, which GCodeClean is now tripping over. If you want to PM me with that file I can try some testing with it.

I used GCodeClean-master.zip and Get this message now:05_Mill_Well.bat (82 Bytes) 05_Mill_Well.txt (1.1 MB)
C:\Users\james\OneDrive\Documents\GCodeClean-master07DEC2020OK\GCodeClean-master\CLI>dotnet restore
Determining projects to restore…
C:\Users\james\OneDrive\Documents\GCodeClean-master07DEC2020OK\GCodeClean-master\CLI\gcodecleancli.csproj : error NU1201: Project gcodeclean is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project gcodeclean supports: net5.0 (.NETCoreApp,Version=v5.0)
C:\Users\james\OneDrive\Documents\GCodeClean-master07DEC2020OK\GCodeClean-master\CLI\gcodecleancli.csproj : error NU1201: Project gcodeclean is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / linux-x64. Project gcodeclean supports: net5.0 (.NETCoreApp,Version=v5.0)
C:\Users\james\OneDrive\Documents\GCodeClean-master07DEC2020OK\GCodeClean-master\CLI\gcodecleancli.csproj : error NU1201: Project gcodeclean is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / osx-x64. Project gcodeclean supports: net5.0 (.NETCoreApp,Version=v5.0)
C:\Users\james\OneDrive\Documents\GCodeClean-master07DEC2020OK\GCodeClean-master\CLI\gcodecleancli.csproj : error NU1201: Project gcodeclean is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / win10-x64. Project gcodeclean supports: net5.0 (.NETCoreApp,Version=v5.0)
Failed to restore C:\Users\james\OneDrive\Documents\GCodeClean-master07DEC2020OK\GCodeClean-master\CLI\gcodecleancli.csproj (in 320 ms).
1 of 2 projects are up-to-date for restore.

Glad to be of assistance :slight_smile:

That’s pretty much the answer to your problems right there.
The whole thing has been upgraded to .Net 5 (net5.0) from .Net Core 3.1 (netcoreapp3.1).
So because you’re building this yourself you’ll need to get the .Net 5 SDK and use it instead of the .Net Core 3.1 SDK.

If you are not using the .Net Core 3.1 SDK for anything else I’d recommend that you uninstall it first.

If you go here: Download .NET (Linux, macOS, and Windows) (microsoft.com) you can get the 5.0 SDK

GCodeClean-master07DEC2020 still gives the previous message even though I also installed Runtime 5.0.0 as requested.
As you can see from the attached files, I installed .NET SDK 5.0.100 11/24/2020 when you first told us.
My GCodeClean-master30Nov2020 download gives the message below the first time I run it and then runs perfectly from then on using multiple G-code files.
C:\Users\james\OneDrive\Documents\GCodeClean-master30Nov2020\GCodeClean-master\CLI\Program.cs(38,35): warning CA1303: Method ‘Task Program.RunAsync(Options options)’ passes a literal string as parameter ‘value’ of a call to ‘void Console.WriteLine(string value)’. Retrieve the following string(s) from a resource table instead: “The path to the token definitions JSON file is missing. Proper clipping and annotating of the GCode cannot be performed.”. [C:\Users\james\OneDrive\Documents\GCodeClean-master30Nov2020\GCodeClean-master\CLI\gcodecleancli.csproj]
C:\Users\james\OneDrive\Documents\GCodeClean-master30Nov2020\GCodeClean-master\CLI\Program.cs(105,31): warning CA1303: Method ‘Task Program.RunAsync(Options options)’ passes a literal string as parameter ‘value’ of a call to ‘void Console.WriteLine(string value)’. Retrieve the following string(s) from a resource table instead: “All tolerance and clamping values may be further adjusted to allow for inches vs. millimeters”. [C:\Users\james\OneDrive\Documents\GCodeClean-master30Nov2020\GCodeClean-master\CLI\gcodecleancli.csproj]

netrun netsdk

This is just a warning as it says. It’s because I haven’t taken those messages about the token definitions and clamping values and stuck that into a resource file somewhere.

I downloaded a clean copy and called it GCodeClean-master09DEC2020.zip
Unzipped and put only my two files in it. It ran and only went as far as (Preamble completed by GCodeClean) All three are attached. Put four more in and ran them
all those are attached. Tried to be a scientific as possible.07_slot_cutting.bat (85 Bytes) 07_slot_cutting.txt (1.6 KB) 07_slot_cutting-gcc.txt (66 Bytes) Ammosign.bat (77 Bytes) Ammosign.nc (2.7 MB) Ammosign-gcc.nc (112 Bytes)
C:\Users\james\OneDrive\Documents\GCodeClean-master09DEC2020\GCodeClean-master\CLI>dotnet restore
Determining projects to restore…
All projects are up-to-date for restore.

C:\Users\james\OneDrive\Documents\GCodeClean-master09DEC2020\GCodeClean-master\CLI>pause
Press any key to continue . . .

C:\Users\james\OneDrive\Documents\GCodeClean-master09DEC2020\GCodeClean-master\CLI>dotnet run – --filename 05_Mill_Well.txt --annotate
Outputting to:05_Mill_Well-gcc.txt
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.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Text.Json.JsonElement.GetProperty(String propertyName)
at GCodeClean.Processing.Processing.Annotate(IAsyncEnumerable1 tokenisedLines, JsonElement tokenDefinitions)+MoveNext() in C:\Users\james\OneDrive\Documents\GCodeClean-maste09DEC2020r\GCodeClean-master\GCodeClean\Processing\Processing.cs:line 438 at GCodeClean.Processing.Processing.Annotate(IAsyncEnumerable1 tokenisedLines, JsonElement tokenDefinitions)+MoveNext() in C:\Users\james\OneDrive\Documents\GCodeClean-maste09DEC2020r\GCodeClean-master\GCodeClean\Processing\Processing.cs:line 424
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 C:\Users\james\OneDrive\Documents\GCodeClean-maste09DEC2020r\GCodeClean-master\GCodeClean\Processing\Tokeniser.cs:line 65
at GCodeClean.Processing.Tokeniser.JoinLines(IAsyncEnumerable1 tokenisedLines, String minimisationStrategy)+MoveNext() in C:\Users\james\OneDrive\Documents\GCodeClean-maste09DEC2020r\GCodeClean-master\GCodeClean\Processing\Tokeniser.cs:line 65 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 C:\Users\james\OneDrive\Documents\GCodeClean-maste09DEC2020r\GCodeClean-master\GCodeClean\IO\AsyncTextFile.cs:line 36 at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+MoveNext() in C:\Users\james\OneDrive\Documents\GCodeClean-maste09DEC2020r\GCodeClean-master\GCodeClean\IO\AsyncTextFile.cs:line 36
at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+MoveNext() in C:\Users\james\OneDrive\Documents\GCodeClean-maste09DEC2020r\GCodeClean-master\GCodeClean\IO\AsyncTextFile.cs:line 41 at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+MoveNext() in C:\Users\james\OneDrive\Documents\GCodeClean-maste09DEC2020r\GCodeClean-master\GCodeClean\IO\AsyncTextFile.cs:line 41
at GCodeClean.IO.AsyncTextFile.WriteLinesAsync(String path, IAsyncEnumerable1 lines)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at GCodeCleanCLI.Program.RunAsync(Options options) in C:\Users\james\OneDrive\Documents\GCodeClean-master09DEC2020\GCodeClean-master\CLI\Program.cs:line 149 at GCodeCleanCLI.Program.RunAsync(Options options) in C:\Users\james\OneDrive\Documents\GCodeClean-master09DEC2020\GCodeClean-master\CLI\Program.cs:line 149 at CommandLine.ParserResultExtensions.WithParsedAsync[T](ParserResult1 result, Func`2 action)
at GCodeCleanCLI.Program.Main(String[] args) in C:\Users\james\OneDrive\Documents\GCodeClean-master09DEC2020\GCodeClean-master\CLI\Program.cs:line 28
at GCodeCleanCLI.Program.(String[] args)

C:\Users\james\OneDrive\Documents\GCodeClean-master09DEC2020\GCodeClean-master\CLI>pause
Press any key to continue . . .05_Mill_Well.bat (82 Bytes) 05_Mill_Well.txt (1.1 MB) 05_Mill_Well-gcc.txt (422 Bytes)

Sorry to be a bother but I got this message and results are still the same.
C:\Users\james\OneDrive\Documents\GCodeClean-master09DEC2020OK\GCodeClean-master\CLI>dotnet restore
Welcome to .NET 5.0!

SDK Version: 5.0.101
Telemetry

The .NET tools collect usage data in order to help us improve your experience.
It is collected by Microsoft and shared with the community.
You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to ‘1’ or ‘true’ using your favorite shell.

Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run ‘dotnet dev-certs https --trust’ (Windows and macOS only).
Microsoft Windows [Version 10.0.19041.630]
© 2020 Microsoft Corporation. All rights reserved.
C:\Users\james>dotnet dev-certs https --trust
Trusting the HTTPS development certificate was requested.
A confirmation prompt will be displayed if the certificate was not previously trusted.
Click yes on the prompt to trust the certificate.
A valid HTTPS certificate is already present.
C:\Users\james>

OK - well for this one, GCodeClean does not need ASP.NET Core.

Thanks, I’ll grab these and check them out myself.

OK, so the problem occurs when --annotate tries to find the definition for a code that is not in the tokendefinitions file. This should have simply ignored it and moved on, but it crashed instead.
So I have a fix for that and it will go up shortly.

Next, if you are not actually editing the GCodeClean code yourself I would recommend that you download the prebuilt Windows executable that I do. No need for dotnet restore or dotnet run ..., just run the CLI with the same options.

OK, that’s fixed. Unless you need to change the code I recommend sticking with the actual release - like this one: gcodeclean-win-x64-standalone.zip (github.com)

Fixes a bug found by @jameskylecummings where the --annotate option would blow up if it didn’t recognise a particular GCode (e.g. when the command is not defined in tokenDefinitions.json).
Thanks for the samples James

Release Fix Annotate for unknown codes · md8n/GCodeClean (github.com)

Apparently, I am not clever enough to figure out gcodeclean-win-x64-standalone.zip
CLI.exe opens and closes a window and nothing more
No ReadMe instructions
I can get GCodeClean-0.9.1 to work
Sorry

Open the command prompt window first (in the correct folder), and then try running CLI.exe through that. It will show instruction.

I made a .bat file like this and put it in with the code for gcodeclean-win-x64-standalone
CLI.exe
pause
CLI.exe – --filename 05_Mill_M4_Well.txt --annotate
pause
It worked perfectly.

Your help was off a little bit.
This is not correct:
USAGE:
Clean GCode file:
GCodeClean --filename facade.nc

My input file was 432,732 lines and output 332,499 lines
So it cleaned it up significantly.
Thanks for your efforts.

Version 0.9.3 has been released Release Support Parameters · md8n/GCodeClean (github.com)

  • This includes improvements to the README (so that’s up to date).
  • The preamble will get an +ve Z value injected into it if the first movement command is a G0
  • And the tokeniser now supports defining and using parameters, the things that start with a #.

Not sure if any of the Maslow processors support parameters, but I did want better support for the NIST spec so there you go.

2 Likes