Skip to content

Instantly share code, notes, and snippets.

@Uko
Last active February 2, 2020 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Uko/bc33e41d83d38782cc00650bd808645f to your computer and use it in GitHub Desktop.
Save Uko/bc33e41d83d38782cc00650bd808645f to your computer and use it in GitHub Desktop.
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