# DRILL.PL August 24, 2004 v1.00 # This takes Excellon drill files (as generated by Easytrax) # and turns them into X,Y cords. Add a G81 to taste. # # www.microstepping.com - ncs2004(at)microstepping.com # # Usage: "PERL DRILL.PL inputfile" # Output will have .cnc extension. # # You might have to flip the sign of your Y axis when drilling. # # This does not 'optimize' the drilling path. # An optimized way to generate the output file # would be to store X,Y pairs in an array, get the starting hole # from the user, and then generate the output file by computing # the distance from the current hole to every other hole in the file, # finding the closest hole each time, until all holes have been # accounted for. # # @myt=localtime(time); $ts=$myt[4]+1; #create time string $ts.="/$myt[3]/0"; $ts.=($myt[5]-100); #year, this will fail in 2010 $inputfile=$ARGV[0] || "drill.txt"; $outputfile=$inputfile; $outputfile=~s/\.\w\w\w$//; $outputfile.=".cnc"; open(DATA,$inputfile)||die "Could't open $inputfile. Aborting. \n"; open(DATAOUT,"> $outputfile"); print DATAOUT ";------------------------------------\n"; print DATAOUT "; PCB Drill file\n"; print DATAOUT "; File: $inputfile Date: $ts \n"; print DATAOUT ";------------------------------------\n"; print DATAOUT "; Change the G92 at the beginning of this file to take \n"; print DATAOUT "; care of the board offset.\n"; print DATAOUT "; Then edit G81 x y R0.050 Z-0.1 F5 as appropriate for your setup.\n\n"; print DATAOUT ";------------------------------------\n"; print DATAOUT "G92 X0 Y0\n"; print DATAOUT "G81 X Y R0.010 Z-0.100 F5 ; Edit this line as necessary.\n"; $spaces=" " x 50; $ln=100; while () { $linenumber="N".$ln."0 "; $ln++; $raw=$_; $d=$_; chop ($d); $output=""; if ($d =~ /^[XY]/) { if ($d =~ /^Y/) #does the line start with Y? { $d=~s/(Y\d\d)(.*)/$1\.$2/; $output=$old_x." ".$d; $old_y=$d; } elsif($d =~/Y/) #is there a Y in the line? { $d=~s/(X\d\d)(\d*)(Y\d\d)(\d*)/$1\.$2 $3\.$4/; $old_x=$1.".".$2; $old_y=$3.".".$4; $output=$d; } else #it is X only! { $d=~s/(X\d\d)(.*)/$1\.$2/; $output=$d." ".$old_y; $old_x=$d; } } $output=substr($output.$spaces,0,20); print DATAOUT $linenumber.$output."; --- ".$raw; } print DATAOUT "\n; Add a G0 code here to go back to the first hole\n"; print DATAOUT "M02\n"; print DATAOUT ";------------------------\n"; close DATA; close DATAOUT; $ln-=100; #line count print "Done! $ln lines in output file $outputfile\n";