use Getopt::Long; #Filenames and Variables $file123="mendel4.gcode"; ######## output file such as “whistlestack.gcode”. Will overwrite if another file has the same name. $float="mendel4float.txt"; #float file. ####### float file. Name this something similar to your gcode , like “whistlefloat.txt” $file1="frame-vertex_6off_export.gcode";###### input gcode file, generated by skeinforge my $zstack=4; ######### number of parts you wish to print. my $floatbottom=0.65;#######Z distance from last gcode layer and float layer, 0.7 suggested for easy separation my $floattop=0.25;######Z distance from float layer to next part first layer, 0.36 suggested assuming post-processing to trim from top part my $production=0;#######production switch 0=off, 1=start and end at same height #Open float files open(FLOAT, "<$float") || die("Could not open $float!"); @floatarray = ; chomp (@floatarray); close(FLOAT); #Create Output File open (OUTPUT, ">$file123") or die ("Can't open $file123!\n"); select (STDOUT); #setup file names $filearray[$j]=$j; $filearray[$j] =~ tr/1-9/a-z/; #declare variables/files my @array = (); my @object = (); my $NewZ = 0; my $OldZ = 0; my $BottomZ = 0; my $object1 = 0; my $ztest = 0; my $MarkZ=0; my $objectZ0=0; my $toler=110; #open files open(FILE1, "<$file1") || die("Could not open $file1!"); @F1 = ; chomp (@F1); close(FILE1); #Put initial into initial array for ($i = 0; $F1[$i] ne "()"; $i++) { $initial[$i] = $F1[$i]; } $F1[$i+1] =~ m/(Z)()([0-9]+\.+[0-9]+)/; $objectZ = $3; print "the object starts at $objectZ\n"; #Put object into object array $k=0; for (i; $i <= ($#F1-5); $i++) { $object[$k] = $F1[$i]; $k++; } #Put end into end array $k=0; for (i; $i <= ($#F1); $i++) { $end[$k] = $F1[$i]; $k++; } print "$i lines in gcode \n"; select (OUTPUT); #Print for ($i = 0; $i <= $#initial; $i++) { print "$initial[$i]\n"; } for ($j = 1; $j <= $zstack; $j++) { if ($j > 1) { for ($i = 0; $i <= $#floatarray; $i++) { chomp($NewZ=$OldZ+$floatbottom); $floatarray[$i] =~ s/(Z)([0-9]+\.+[0-9]+)/Z$NewZ/; print "$floatarray[$i]\n"; } } chomp($BottomZ = $NewZ); for ($i = 0; $i <= $#object; $i++) { $object[$i] =~ m/(Z)([0-9]+\.+[0-9]+)/; $object1=$object[$i]; if ($2 > 0) { $NewZ=$2; if ($j > 1) { if ($2 > 0) {chomp($NewZ=$2+$BottomZ-1.2+$floattop);} if ($NewZ > $toler) {die("gcode above z-tolerance please decrease stack")}; $object1 =~ s/(Z)([0-9]+\.+[0-9]+)/Z$NewZ/; } } print "$object1\n"; } $OldZ=$NewZ; select (STDOUT); print "Z= $OldZ mm at top of part $j\n"; select (OUTPUT); } $MarkZ=int($OldZ/10 + 1)*10; select (STDOUT); print "Final position will be Z= $MarkZ mm\n"; select (OUTPUT); for ($i = 0; $i <= $#end; $i++) { $end[$i] =~ s/G91/G90/; $end[$i] =~ s/(Z)([0-9]+)/Z$MarkZ/; $end[$i] =~ s/(X)([0-9]+\.+[0-9]+)/X0.0/; $end[$i] =~ s/(Y)([0-9]+\.+[0-9]+)/Y0.0/; $end[$i] =~ s/(X)(-[0-9]+\.+[0-9]+)/X0.0/; $end[$i] =~ s/(Y)(-[0-9]+\.+[0-9]+)/Y0.0/; print "$end[$i]\n"; } close OUTPUT; #Production Section reads file and changes initial z-coordinate if ($production == 1) { open (FILE123, "<$file123") or die "Can't open $file123!\n"; @F123 = ; chomp (@F123); close(FILE123); open (OUTPUT, ">$file123") or die "Can't open $file123!\n"; select (OUTPUT); for ($i = 0; $i <= $#F123; $i++) { $F123[$i] =~ s/(FIRST SET Z TO )([0-9]+)/FIRST SET Z TO $MarkZ/; $F123[$i] =~ s/(You are now at 0,0,)([0-9]+)/You are now at 0,0,$MarkZ/; if ($ztest == 0 && $F123[$i] =~ m/(Z)([0-9]+)/ ) { $F123[$i] =~ s/(Z)([0-9]+)/Z$MarkZ/; $ztest = 1; } print "$F123[$i]\n"; } close (OUTPUT); } select (STDOUT); print "$file123 DONE!\n";