Last active
February 2, 2020 22:29
-
-
Save Uko/bc33e41d83d38782cc00650bd808645f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colorChangeIndex := self detectIndex: [ :s | s = '; PRINT_COLOR_CHANGE' ]. | |
startLines := self first: colorChangeIndex-1. | |
restLines := self allButFirst: colorChangeIndex + 1. | |
layerChangeIndex := restLines detectIndex: [ :s | s = ';AFTER_LAYER_CHANGE' ]. | |
endLines := restLines allButFirst: layerChangeIndex. | |
layerLines := restLines first: layerChangeIndex. | |
brokenObjects := (layerLines splitOn: [ :s | s beginsWith: '; printing object ' ]) reject: #isEmpty. | |
intermediateObjects := { brokenObjects first } , (brokenObjects allButFirst flatCollect: [ :lines | { lines first: 4 . lines allButFirst: 4 } ]). | |
fixedObjects := (intermediateObjects pairsCollect: [ :first :second | first , second ]), { intermediateObjects last }. | |
partitionedObjects := fixedObjects collect: [ :lines | | infillIndex | | |
infillIndex := lines detectIndex: [ :s | s endsWith: '; move to first infill point' ]. | |
{ lines first: infillIndex - 1 . lines allButFirst: infillIndex - 1 } ]. | |
newLines := | |
startLines, | |
(partitionedObjects flatCollect: #first), | |
{ 'M600' }, | |
(partitionedObjects flatCollect: #second), | |
{ 'M600' }, | |
endLines. | |
(FileSystem disk workingDirectory / 'COIN-2020_x9_MMX_0.1mm_PLA_MK3_12h7m.gcode') writeStream | |
nextPutAll: (newLines joinUsing: String cr); | |
close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment