My Print Grew a Head... A Moai Head Actually


#21

OK, I’ve written a small Powershell script that uses a regular expression to find and replace all non-zero E values in a Gcode file.

It isn’t as fast as a fully compiled C++ program but it gets through large files at an acceptable clip - see screenshot below:-

Before:-

image

After:-

image

The reduction in file size is a little over 17%

I’m running a test print now with the modified file to check that there aren’t any issues with it.


#22

look forward to the print results.


#23

The print of the modified file ran without any problems:-

Looks like modifying the gcode E values is fine. I’ll paste the PowerShell script code directly below for anyone else who is interested in experimenting with this. As always though, this script is provided with NO warranty of suitability - use it at you own risk! On the flip-side of that statement - modify and distribute it however you like:-

$stopWatch = [System.Diagnostics.Stopwatch]::StartNew()
$inputFile = "M:\01\544\13\ZH\01-544-13-ZH100_SUP.gcode"
$outputFile = "M:\01\544\13\ZH\01-544-13-ZH100_SML.gcode"
try
{
    $stringReader = [IO.File]::OpenText($inputFile)
    $stringWriter = New-Object System.IO.StreamWriter($outputFile)
    $SearchStr = "E([0-9]+\.[0-9]*[1-9][0-9]*)"
    $ReplaceStr = "E1.0"

    while ($stringReader.Peek() -ge 0)
    {
        $inputLine = $stringReader.ReadLine()
        $outputLine = $inputLine -replace $SearchStr, $ReplaceStr
        $stringWriter.writeline($outputLine)
    }
}
finally
{
    $stringReader.Close()
    $stringWriter.Close()
}

$inputFileLength = (Get-Item $inputFile).length/1KB
$outputFileLength = (Get-Item $outputFile).length/1KB

$inputFileData = "Input file size: " + [math]::Round($inputFileLength) + " KB"
$outputFileData = "Output file size: " + [math]::Round($outputFileLength) + " KB"

$percentSizeDiff = "Size Reduction: " + [math]::Round((($inputFileLength - $outputFileLength)/$inputFileLength)*100) + "%"

$inputFileData
$outputFileData
$percentSizeDiff

$stopWatch.Stop()
$stopWatch.Elapsed