Last active
October 26, 2022 12:43
-
-
Save boverby/2d4e5b3eb3b40bea7d01c5e240bc5311 to your computer and use it in GitHub Desktop.
remind yourself what config changes you made to superslicer
This file contains hidden or 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
#!/bin/perl | |
use strict; | |
use warnings; | |
# changedConfigHadron.pl | |
## sometimes I forget when (or what ) manual changes were made in superslicer. | |
## but since I always put the gcode into the same working directory, you can | |
## basically just look for differences for a diff between chronolocal files | |
## to see how the settings have evolved | |
## credit to https://github.com/supermerill/SuperSlicer | |
use Data::Dumper; | |
use File::Basename; | |
#------------------start of-- local configuration --------------------------------------- | |
my $GCODE_DIRECTORY='/mnt/archives/gcode/hadron'; # my working directory | |
my $MATCHPATTERN='; SuperSlicer_config = begin'; # flag superslicer puts at beginning of list | |
#------------------end of --- local configuration --------------------------------------- | |
my @files = `ls -rt ${GCODE_DIRECTORY}/*.gcode`; | |
chomp @files; | |
#print STDERR Dumper( \@files ) . "\n"; | |
###### | |
## read earliest chronological file for initial config, make hash | |
###### | |
my $init_file = shift(@files); | |
print " ==initFile=== $init_file ======================\n"; | |
my %initialConfig = %{ makeHashOfConfigFile( $init_file ) }; | |
#### | |
## loop thru remaining files comparing to initial config | |
#### | |
for my $f ( @files ){ | |
my $ts = `date -r "${f}" "+%Y%m%d_%H%M%S" `; chomp $ts; | |
my $root_name = basename($f, ".gcode" ); | |
$root_name =~ s/_.*$// ; | |
my %tempHash = %{ makeHashOfConfigFile( "$f" ) }; | |
#print Dumper (\%tempHash ) ."\n";; | |
my @report = compare_hashes(\%initialConfig, \%tempHash); | |
if ( scalar @report == 0 ) { | |
push @report, "----- NO CHANGES -------"; | |
} | |
print " ============= $f ======================\n"; | |
print " report for $root_name ($ts)\n"; | |
print join "\n", @report; | |
print "\n\n"; | |
%initialConfig = %tempHash; | |
} | |
########################################################## | |
## make hash of config | |
########################################################## | |
sub makeHashOfConfigFile { | |
my ($fn) = @_; | |
my %h; | |
my @lines = `sed -n '/${MATCHPATTERN}/,\$p' "${fn}"`; | |
chomp @lines; | |
foreach (@lines){ | |
next if /SuperSlicer_config/; | |
$_ =~ s/^; // ; # remove leading semicolon | |
#print STDERR">>>> ". $_ . "\n"; | |
my ($attr,$val) = split( /\s*=\s*/ ,$_, 2); | |
#print STDERR"---- |$attr| = |$val|\n"; | |
$h{$attr} = $val ; | |
} | |
return \%h; | |
} | |
########################################################## | |
## see https://code-maven.com/slides/perl/compare-hashes | |
########################################################## | |
sub compare_hashes { | |
my ($first, $second) = @_; | |
my @report; | |
foreach my $k (keys %{ $first }) { | |
if (not exists $second->{$k}) { | |
push @report, " The key '$k' does not exist in second hash"; | |
} elsif (not defined $first->{$k} and not defined $second->{$k}) { | |
# ok, neither is defined | |
} elsif (defined $first->{$k} and not defined $second->{$k}) { | |
push @report, | |
" The value of '$k' is '$first->{$k}' in the first hash" | |
. " and undef in the second hash"; | |
} elsif (not defined $first->{$k} and defined $second->{$k}) { | |
push @report, | |
" The value of '$k' is '$second->{$k}' in the second hash" | |
. " and undef in the first hash"; | |
} elsif ($first->{$k} ne $second->{$k}) { | |
push @report, | |
" The value of '$k' differs: '$first->{$k}' changed to '$second->{$k}'"; | |
} | |
} | |
foreach my $k (keys %{ $second }) { | |
if (not exists $first->{$k}) { | |
push @report, " The key '$k' does not exist in first hash"; | |
} | |
} | |
return @report; | |
} | |
=pod | |
example output: | |
============= /mnt/archives/gcode/hadron/zbandingStack_4wall_020.gcode ====================== | |
report for zbandingStack (20221025_112632) | |
The value of 'top_solid_layers' differs: '3' changed to '0' | |
The value of 'fill_density' differs: '7.5%' changed to '0%' | |
The value of 'bottom_solid_layers' differs: '3' changed to '0' | |
The value of 'brim_width' differs: '3' changed to '0' | |
============= /mnt/archives/gcode/hadron/zbandingThin_20221025_2wall_020.gcode ====================== | |
report for zbandingThin (20221025_113822) | |
The value of 'perimeters' differs: '4' changed to '2' | |
============= /mnt/archives/gcode/hadron/zbandingThin_20221025_2wall_021.gcode ====================== | |
report for zbandingThin (20221025_113918) | |
The value of 'layer_height' differs: '0.2' changed to '0.21' | |
============= /mnt/archives/gcode/hadron/zbandingThin_20221025_2wall_028.gcode ====================== | |
report for zbandingThin (20221025_113952) | |
The value of 'layer_height' differs: '0.21' changed to '0.28' | |
============= /mnt/archives/gcode/hadron/lrs-box-slice_20221025-132352_ss.gcode ====================== | |
report for lrs-box-slice (20221025_131928) | |
The value of 'brim_width' differs: '0' changed to '2' | |
The value of 'perimeters' differs: '2' changed to '4' | |
The value of 'top_solid_layers' differs: '0' changed to '1' | |
The value of 'bottom_solid_layers' differs: '0' changed to '2' | |
The value of 'fill_density' differs: '0%' changed to '5.5%' | |
============= /mnt/archives/gcode/hadron/BlindsAssy_20221025-155512_ss.gcode ====================== | |
report for BlindsAssy (20221025_155332) | |
The value of 'brim_width' differs: '2' changed to '0' | |
The value of 'bottom_solid_layers' differs: '2' changed to '0' | |
The value of 'top_solid_layers' differs: '1' changed to '3' | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
added example output for clarity