~rabbits/orca-rack

2fe1f6bc88bc5987c2586b8d88860f32013810aa — Andrew Alderwick 1 year, 8 months ago 039beb5
Add little helper script to sort footprint pads.
2 files changed, 22 insertions(+), 0 deletions(-)

A electronics/kicad/etc/.gitignore
A electronics/kicad/etc/sort-pads.moon
A electronics/kicad/etc/.gitignore => electronics/kicad/etc/.gitignore +1 -0
@@ 0,0 1,1 @@
*.lua

A electronics/kicad/etc/sort-pads.moon => electronics/kicad/etc/sort-pads.moon +21 -0
@@ 0,0 1,21 @@
preamble, entries, postamble = {}, {}, {}

for l in assert io.lines arg[1]
    t = l\match'^  %(pad' and entries or #entries > 0 and postamble or preamble
    table.insert t, l

table.sort entries, (a, b) ->
    ax, ay = a\match '%(at (%-?[%d.]+) (%-?[%d.]+)%)'
    bx, by = b\match '%(at (%-?[%d.]+) (%-?[%d.]+)%)'
    if not ax or not bx
        error 'no at found'
    if ax == bx
        return tonumber(ay) < tonumber(by)
    return tonumber(ax) < tonumber(bx)

for l in *preamble
    print l
for l in *entries
    print l
for l in *postamble
    print l