← Back to team overview

kicad-developers team mailing list archive

Plot and drill file generation via scripts

 

Hi folks,

One of the tasks I've been doing for Wayne and Layne for Kicad is
command line plot and drill generation.  Internally, we're going to
use it to generate files upon commit to better track progress in the
distributed team, but externally, we're working with a friend of ours
who runs a PCB order service. He usually takes gerbers and drill
files, but through his web interface, you can upload Eagle files and
it'll "do the right thing" and show you an automatic preview and
everything.  We're trying to let him do the same for Kicad.

This required a few changes, and we've made what we think is the
minimal set of changes in Kicad to do this.

The patch is attached, and we believe it matches coding standards.
It's based off of r4123 from last night.

Quickly highlighting the changes we made:

 * Added a few files to the scripting interface and a typemap so FILE
* in C++ turns into file objects in Python
 * Moved GetGerberExtension to common_plot_functions.cpp.  I tried
just exporting the plot file it was in, and had some issues.
 * I moved the fclose outside of CreateDrillFile in
gendrill_Excellon_writer.cpp.
This was causing issues in Python. I added an fclose after each time
CreateDrillFile was called.  You pass in a file handle, so I think this is
probably ok.
 * Overloaded PLOT_CONTROLLER::OpenPlotfile so it will take a file extension.

Future work:
 * There is a good amount of logic in the dialogs, for both plotting
and drill file generation.  Because of this, I had to redo some logic
in the Python program.  While there is more testing to be done before
I hand this off to the PCB order service, I'd like to minimize the
logic in python for this--if something changes in Kicad regarding
these files, like the recent NPTH/TH two file drill generation, I
would prefer the Python script to automatically "do the right thing".
However, I'm comfortable maintaining these scripts and watching for
regressions with each build--the Wayne and Layne build cluster already
does this for the Kicad packages.
 * The scripts are not complete.  Right now, they're mostly untested,
but they prove out the concept.  Some of the arguments are unintuitive.
If you use the scripts provided, and they explode your computer,
I told you so.  If there isn't serious pushback to the concept, I'll polish
the scripts up over the next few days and release them along with
their tests.

Please let me know if there's anything I can do to help this along.

What do you think folks?

wolf@willow:~ $ ./plot.py -h
usage: plot.py [-h] [--format {gerber}] [--verbose]
               [--exclude-edge-from-other-layers]
               [--plot-sheet-reference PLOT_SHEET_REFERENCE]
               [--plot-in-silk
{pads,module-value,module-reference,other-module-texts,invisible-texts}]
               [--layers
{all,B.Adhes,B.Cu,B.Mask,B.Paste,B.SilkS,Cmts.User,Dwgs.User,Eco1.User,Eco2.User,Edge.Cuts,F.Adhes,F.Cu,F.Mask,F.Paste,F.SilkS,Inner1.Cu}]
               [--use-auxiliary-axis-as-origin]
               [--subtract-soldermask-from-silk]
               FILE

Eventually, this will be a slick way to generate plot files for Kicad from the
command line. Currently, it's untested and a proof-of-concept only, but it
generates Gerbers. Do not use this, really, for anything. Do not use with
files that aren't backed up.

positional arguments:
  FILE                  Kicad board file (.kicad_pcb or .brd)

optional arguments:
  -h, --help            show this help message and exit
  --format {gerber}     Selects the plot format. Only a single format per run
                        is supported. Only gerber is currently supported.
  --verbose, -v         Increase verbosity. May be entered multiple times.
  --exclude-edge-from-other-layers
                        Exclude PCB edge layer from other layers.
  --plot-sheet-reference PLOT_SHEET_REFERENCE
                        Plot sheet reference on all layers.
  --plot-in-silk
{pads,module-value,module-reference,other-module-texts,invisible-texts}
                        Plot pads on silkscreen.
  --layers {all,B.Adhes,B.Cu,B.Mask,B.Paste,B.SilkS,Cmts.User,Dwgs.User,Eco1.User,Eco2.User,Edge.Cuts,F.Adhes,F.Cu,F.Mask,F.Paste,F.SilkS,Inner1.Cu}
                        Select layers to plot.

gerber options:
  --use-auxiliary-axis-as-origin
  --subtract-soldermask-from-silk

wolf@willow:~ $ ./drill.py -h
usage: drill.py [-h] [--verbose] [--drill-units {millimeters,inches}]
                [--zero-format
{decimal-format,keep-zeros,suppress-leading-zeros,suppress-trailing-zeros}]
                [--mirror-y-axis] [--minimal-header]
                [--drill-origin {absolute,auxillary-axis}]
                [--output-prefix OUTPUT_PREFIX] [--output-dir OUTPUT_DIR]
                [--force FORCE]
                FILE

Eventually, this will be a slick way to generate drill files for Kicad from
the command line. Currently, it's untested and a proof-of-concept only. Do not
use this, really, for anything. Do not use with files that aren't backed up.

positional arguments:
  FILE                  Kicad board file (.kicad_pcb or .brd)

optional arguments:
  -h, --help            show this help message and exit
  --verbose, -v         Increase verbosity. May be entered multiple times.
  --drill-units {millimeters,inches}, -u {millimeters,inches}
                        Select the drill file units. Defaults to inches.
  --zero-format
{decimal-format,keep-zeros,suppress-leading-zeros,suppress-trailing-zeros},
-z {decimal-format,keep-zeros,suppress-leading-zeros,suppress-trailing-zeros}
                        Select the zero format.
  --mirror-y-axis, -m   Select whether to mirror the y axis. Defaults to
                        false.
  --minimal-header, -s  Enable a minimal header on the output drill file.
  --drill-origin {absolute,auxillary-axis}, -c {absolute,auxillary-axis}
                        Select the drill origin. Defaults to absolute.
  --output-prefix OUTPUT_PREFIX, -n OUTPUT_PREFIX
                        The prefix for the output file(s). NPTH drill files
                        will have -NPTH.drl appended, while standard drill
                        files will have .drl appended. Defaults to the name of
                        the PCB.
  --output-dir OUTPUT_DIR, -d OUTPUT_DIR
                        The output directory. Defaults to the current
                        directory.
  --force FORCE         Do not use this option. When a fatal error is
                        encountered, this option stops the script from
                        stopping. This will almost certainly generate
                        incorrect, broken files.

Adam Wolf
Wayne and Layne, LLC

Attachment: drill.py
Description: Binary data

Attachment: plot.py
Description: Binary data

Attachment: drillplotscripting.diff
Description: Binary data


Follow ups