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


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:-





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.


look forward to the print results.


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"
    $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

$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) + "%"