A couple months ago I wrote a similar script in the TCL language. It can take an excellon file from Eagle, and convert it to a bunch of G-code circle cuts, offset for a known mill bit size, optionally with multiple plunges depths for thicker boards. As I recall, I used the excellon format, as it contained the drill sizes in the same file, but otherwise it's very similar to gerber.
My script kind of relies on a larger suite of TCL scripts I've made for vertical milling, though. They create a kind of mid-level language for milling things. I can tell it I want circles and polygons cut out to a given depth, with a given material, using a given mill bit, and it works out the G-code for it, including feeds, speeds, multiple plunge depth cuts, and inset pocket clearing. It's not intelligent about merging pockets, though.
The main trick in eagle, was telling it to not make vias smaller than
1/32nd inch in size, which is the size of the mill bit I used.
My script follows. You'll need to make a new mlcnc_g_circle proc to output the G-code for the individual circles, with moves in between. My scripts to do that are quite involved, and take into account all sorts of stuff like mill bit type and coating, stock material, cut depth, and such, which you don't really need for this, and which would take up a lot more space here. If I had more time, I would whip up a simplified mlcnc_g_circle proc.
- Garth
# filename is the name of the excellon file to convert. # z is the Z depth to cut to. proc mlcnc_g_excellon {filename z} { set f [open $filename "r"] set holesInfo {} set section "start" set conv 1.0 set currdiam 0.0 while {![eof $f]} { if {[catch { set line [gets $f] }]} { break } if {$line == "M71"} { set conv [expr {1.0/25.4}] } elseif {$line == "M72"} { set conv 1.0 } if {[regexp {^ *T *([0-9][0-9]*) *C
*([0-9][0-9]*\\.[0-9][0-9]*).*$} $line dummy toolnum diam]} { set toolnum [string trimleft $toolnum "0"] set diam [expr {$diam+0.0}] set toolsInfo($toolnum) $diam } elseif {[regexp {^ *T *([0-9][0-9]*).*$} $line dummy toolnum]} { set toolnum [string trimleft $toolnum "0"] if {![info exists toolsInfo($toolnum)]} { error "Malformed excellon file. May require extra drill tool file. We don't handle that yet." } set currdiam $toolsInfo($toolnum) } elseif {[regexp {^ *X *([0-9][.0-9]*) *Y
*([0-9][.0-9]*).*$} $line dummy x y]} { if {[string first "." $x] != -1} { set x [expr {$x*$conv}] set y [expr {$y*$conv}] } else { set x [expr {$x*$conv/10000.0}] set y [expr {$y*$conv/10000.0}] } lappend holesInfo $x $y $currdiam } } set out {} foreach {x y diam} $holesInfo { set rad [expr {$diam/2.0}] append out [mlcnc_g_circle $x $y $z $rad $rad] } return $out }
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.