Advertisement
rootiest

temptower.pl

Jul 4th, 2022
1,195
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.83 KB | None
  1. #!/usr/bin/perl -i                                                    
  2.  
  3. # This script extracts settings from the gcode comments shown below.
  4. # The gcode comments should be added to the filament settings start G-Code in Slic3r
  5. # ; Tower temp 280      - set initial temp to 280 (default: print layer temperature)
  6. # ; Tower temp_step -5  - step temperature down 5 degrees for each block
  7. # ; Tower skip 10       - first block is 10 layers higher than others
  8. # ; Tower block 35      - the blocks are 35 layers high
  9. # ; Tower blocks 10     - (optional) emit only 10 blocks
  10.  
  11. # Each layer should begin with
  12. # ; Layer [layer_num]   - where [layer_num] is replaced by the layer number
  13.  
  14. use strict;
  15. use warnings;
  16. $^I = '.bak';
  17.  
  18. my $s_temp = 280;
  19. my $s_temp_step = -5;
  20. my $s_skip = 10;
  21. my $s_block = 35;
  22. my $s_blocks = 0;
  23.  
  24. my $hello = 0;
  25. my $temp = $s_temp;
  26. my $layer = 0;
  27. my $block = 0;
  28. my $suppress = 0;
  29.  
  30. while (<>) {
  31.     if (! $hello) {
  32.         print "; Processed by $0\n";
  33.         $hello = 1;
  34.     }
  35.  
  36.     my $new_layer = 0;
  37.    
  38.     if (/^; Tower temp ([0-9]+)/) {
  39.         $s_temp = $1;
  40.         $temp = $1;
  41.     } elsif (/^; Tower temp_step ([-0-9]+)/) {
  42.         $s_temp_step = $1;
  43.     } elsif (/^; Tower skip ([0-9]+)/) {
  44.         $s_skip = $1;
  45.     } elsif (/^; Tower block ([0-9]+)/) {
  46.         $s_block = $1;
  47.     } elsif (/^; Tower blocks ([0-9]+)/) {
  48.         $s_blocks = $1;
  49.     } elsif (/^; Layer ([0-9]+)/) {
  50.         $layer = $1;
  51.         $new_layer = 1;
  52.     } elsif (/^M104 S([0-9]+)/ && $block == 0) {
  53.         $s_temp = $1;
  54.         $temp = $1;
  55.     } elsif (/^;END gcode for filament/) {
  56.         $suppress = 0;
  57.     }
  58.    
  59.     if ($new_layer && $layer >= $s_skip && (($layer - $s_skip) % $s_block) == 0) {
  60.         $_ = $_ . "M104 S$temp\n";
  61.         if ($block == 0) { $_ = $_ . "M109 S$temp\n"; } # Wait for temperature
  62.         $block ++;
  63.         $temp += $s_temp_step;
  64.     }
  65.    
  66.     print unless $suppress;
  67.    
  68.     if ($s_blocks && $block > $s_blocks) { $suppress = 1; }
  69. }
  70.  
Advertisement
RAW Paste Data Copied
Advertisement