Re: Gerber to G-Code, Help needed.



On Oct 20, 9:30 pm, "chapmjw" <chap...@xxxxxxxxx> wrote:
Every thing works
perfectly from eagle but i'll like to be able to import a gerber file,
then convert to G-Code.


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
}

.



Relevant Pages

  • Re: Converting Eagle scripts between version 4.16 and version 4.09
    ... I have drawn up a schematic using the freeware version of Eagle, ... load or use a netscript to simply load up my schematic in the old ... the scripts between these versions so I can save as a script in 4.16, ...
    (sci.electronics.cad)
  • Re: Help please: CURL lib appends 0 (zero) to all output
    ... Eagle writes: ... I am experiencing a problem: ... > I seem to be unable to get rid of it. ... > Script 2 then processes the data and generates the output. ...
    (alt.php)
  • Re: Help please: CURL lib appends 0 (zero) to all output
    ... Eagle writes: ... I am experiencing a problem: ... > I seem to be unable to get rid of it. ... > Script 2 then processes the data and generates the output. ...
    (comp.lang.php)
  • Re: 64-bit arithmetic in scripts?
    ... Dan Nelson has kindly explained everything: ... I haven't thought about using expr. ... > If you want your script to work on both, you'll have to do a feature ... > calling expr, and finally fall back on calling bc. ...
    (freebsd-questions)
  • Re: 64-bit arithmetic in scripts?
    ... expr does 64-bit math by default. ... If you want your script to work on both, you'll have to do a feature ... calling expr, and finally fall back on calling bc. ...
    (freebsd-questions)