GerbMerge -- A Gerber-file merging program

> Andrew Sterian
> Padnos College of Engineering and Computing
> Grand Valley State University

Top-Level | The Configuration File | The Layout File | Automatic Placement | Version 1.6
| October 6, 2008
Installation | Requirements | Running GerbMerge | Verifying the Output | Limitations | Program Options | Copyright | To Do | Credits | History |

## What's New

In release 1.6:

- The `MinimumFeatureSize` configuration option was introduced in order to support enforcing a minimum thickness for silkscreen layers.
- Negative X/Y co-ordinates in input Gerber files are now supported to allow some Orcad-generated files to be processed.
- Layout files (i.e., DEF files) now support job names that have hyphens in them (but job names cannot begin with hyphens) and job names that start with numbers.
- Layout files (i.e., DEF files) now consider job names to be case-insensitive.
- Python 2.4 is now required.

In release 1.5:

- The `DrillClusterTolerance` configuration option was introduced to reduce the number of drill sizes in the output file.
- Added support for 90, 180, and 270 degree board rotations in the layout file (i.e., the DEF file). Rotated jobs can now be specified as `Rotate` or `Rotate90` for 90-degree rotation, `Rotate180`, or `Rotate270`.
- Fixed a bug that prevented the placement-file approach from working when there were rotated jobs.

In release 1.4:

- Added support for clustering drill sizes in the output file to reduce the number of drills. Clustering tolerance is set by adjusting the TOLERANCE variable in drillcluster.py. NOTE: This approach has been superseded by the `DrillClusterTolerance` configuration option introduced in version 1.5.

In release 1.3:

- Gerber files are now generated in 2.5 format, and are also internally represented in this format for greater accuracy. Excellon files continue to be generated and represented in 2.4 format.
- Fixed a bug in generating scoring files that could result in missing scoring lines.

In release 1.2:

- Preliminary support was added for CAM files generated by Protel, including polygons, layer polarity, and circular interpolation commands.
- Bug fix: For Gerber files in anything other than 2.4 format, drawing commands with repeated, omitted ordinates were incorrectly parsed.

In release 1.1:

- A new `ScoringFile` configuration option was added. This option allows for scoring (V-groove) data to be generated in between individual jobs.

### Bug Fixes

- The widths of lines used to draw cut lines and crop marks was 0mil (instead of the expected default value of 10mil) when these were not explicitly specified in the configuration file.
- The `--place-file` option did not work when job names had uppercase characters.

## Introduction

GerbMerge is a program for combining (panelizing) the CAM data from multiple printed circuit board designs into a single set of CAM files. The purpose of doing so is to submit a single job to a board manufacturer, thereby saving on manufacturing costs.

GerbMerge currently works with:

- CAM data generated by the Eagle circuit board design program, with "best effort" support for Orcad, Protel, and PCB
- Artwork in Gerber RS274-X format
- Drill files in Excellon format

Here is one sample and another sample of the program's output. These samples demonstrate panelizing multiple, different jobs, and also demonstrate board rotation.

You can download the latest version of GerbMerge from:

`http://claymore.engineer.gvsu.edu/~steriana/Python`

## Requirements

GerbMerge is written in pure Python. It depends upon the following packages for operation:

- Python version 2.4 or later
- eGenix mxBase tools version 2.0.4 or later
- SimpleParse version 2.0.0 or later

All of the above packages come with easy installation programs for both Windows and Linux.

## Installation

First, install all of the packages listed above in the Requirements section.

### Windows

Run the `gerbmerge1.6.exe` installation program. I will assume you choose all of the default installation options. The installer will create and populate the following directories:

    c:\Python24\lib\site-packages\gerbmerge
    c:\Python24\gerbmerge

The above assumes you have Python installed in `C:\Python24`. The first directory is where the actual program resides. The second directory contains the documentation, example files, etc. In the `C:\Python24` directory is a sample batch file `GERBMERGE.BAT` which shows you how to run the GerbMerge program.

### Unix

Extract the `gerbmerge1.6.tar.gz` file then install as follows:

`python setup.py install` (You may need to be root to install to system directories)

The installer will create and populate the following directories/files:

    /usr/local/lib/python2.4/site-packages/gerbmerge
    /usr/local/lib/python2.4/gerbmerge
    /usr/local/bin/gerbmerge

The above assumes your Python library directory is as indicated (it may be elsewhere but the installer should be able to find it, so don't worry about it). The first directory is where the actual program resides. The second directory contains the documentation, example files, etc. A sample program for invoking GerbMerge is installed as `/usr/local/bin/gerbmerge`...feel free to move it somewhere else.

## Running GerbMerge

### Windows

Open a DOS box and invoke the Python interpreter on the `gerbmerge.py` file. Have a look at GERBMERGE.BAT (and put this on your Path somewhere) for an example.

    c:\python24\python c:\python24\lib\site-packages\gerbmerge\gerbmerge.py

### Unix

You run GerbMerge by invoking the Python interpreter on the `gerbmerge.py` file of the `gerbmerge` package. For example:

    python /usr/local/lib/python2.4/site-packages/gerbmerge/gerbmerge.py

The `gerbmerge` shell script that comes with this software contains an example for running GerbMerge, modelled on the above. By default, this shell script is installed in `/usr/local/bin` so you should just be able to type `gerbmerge` from a shell prompt.

### Operation

There are three ways to run GerbMerge:

1. By manually specifying the relative placement of jobs
2. By manually specifying the absolute placement of jobs
3. By letting GerbMerge automatically search for a placement that minimizes total panel area

#### Manual Relative Placement

For the manual relative placement approach, GerbMerge needs two input text files:

- The configuration file specifies global options and defines the jobs to be panelized

- The layout file specifies how the jobs are to be laid out.

The names of these files are the two required parameters to GerbMerge:

    gerbmerge file.cfg file.def

The following links describe the contents of the configuration file and layout file.

#### Manual Absolute Placement

For the manual absolute placement approach, GerbMerge also needs the configuration file as well as another text file that specifies where each job is located on the panel and whether or not it is rotated:

    gerbmerge --place-file=place.txt file.cfg

The `place.txt` file looks something like:

    job1 0.100 0.100
    cpu 0.756 0.100
    cpu*rotated 1.35 1.50

This method of placement is not meant for normal use. It can be used to recreate a previous invocation of GerbMerge, since GerbMerge saves its results in a text file (whose name is set in the `[MergeOutputFiles]` section of the configuration file) after every run. Thus, you can experiment with different parameters, save a placement you like, do some more experimentation, then return to the saved placement if necessary.

Alternatively, this method of placement can be used with third-party back ends that implement intelligent auto-placement algorithms, using GerbMerge only for doing the actual panelization.

#### Automatic Placement

For the automatic placement approach, GerbMerge only needs the configuration file:

    gerbmerge file.cfg

Command-line options can be used to modify the search algorithm. See the Automatic Placement page for more information.

### Input File Requirements

GerbMerge requires the following input CAM files:

- Each job must have a Gerber file describing the board outline, which is assumed rectangular. In Eagle, a board outline is usually generated from the Dimension layer. This board outline is a width-0 line describing the physical extents of the board. If you're not using Eagle, you don't have to generate a width-0 rectangle, but GerbMerge does need to use some Gerber layer to determine the extents of the board. GerbMerge will take the maximum extents of all drawn objects in this layer as the extents of the board.

- Each job must have an Excellon drill file.

- Each job can have any number of optional Gerber files describing copper layers, silkscreen, solder masks, etc.

- All files must have the same offset and must be shown looking from the top of the board, i.e., not mirrored.

- Each job may have an optional tool list file indicating the tool names used in the Excellon file and the diameter of each tool. This file is not necessary if tool sizes are embedded in the Excellon file. A typical tool list file looks like:

                T01 0.025in
                T02 0.032in
                T03 0.045in

## Verifying the Output

Before sending your job to be manufactured, it is imperative that you verify the correctness of the output. Remember that GerbMerge comes with NO WARRANTY. Manufacturing circuit boards costs real money and a single mistake can render an entire lot of boards unusable.

I recommend the following programs for viewing the final output data. Take the time to become very familiar with at least one of these tools and to use it before every job you send out for manufacture.

gerbv
  For Linux, the best option (currently) for viewing Gerber and Excellon files is the `gerbv` program. Simply type in the names of all files generated by GerbMerge as parameters to `gerbv`:

      gerbv merged.*.ger merged.*.xln

GC-Prevue

  For Windows, GC-Prevue is a good program that I have used often. It is a free program. GraphiCode makes lots of other, more powerful Gerber manipulation and viewing programs but they are quite pricey ($495 and up).

ViewMate

  Another free Windows program, ViewMate is similar to GC-Prevue. I have not used ViewMate much, but that is mostly due to familiarity with GC-Prevue. The two programs are comparable, although I'm sure that someone who is much more familiar with both could point out some differences.

## Limitations

- This program has mainly been tested with output from the Eagle CAD program. Limited testing has been performed with Orcad, Protel, and PCB. Other CAD programs will NOT WORK with a very high probability, as the input parser is quite primitive.

  If you have the need/motivation to adapt GerbMerge to other CAD programs, have a look at the `gerber2pdf` program. It is written in Python and implements a much more complete RS274-X input file parser. Combining GerbMerge with `gerber2pdf` should be a fairly simple exercise. Also, feel free to send me samples of Gerber/Excellon output of your CAD tool and I'll see if I can add support for it.

- This program handles apertures that are rectangles, ovals, circles, macros without parameters or operators, and Eagle octagons (which are defined using a macro with a single parameter, hence currently handled as a special case).

- The panelizing capabilities of this program do not allow for arbitrary placement of jobs, although there is a fair amount of flexibility.

- All jobs are assumed to be rectangular in shape. Non-rectangular jobs can be handled but will lead to wasted space in the final panel.

- A maximum of 26 different drill sizes is supported for generating a fabrication drawing.

## Program Options

--octagons=normal
--octagons=rotate
  The `--octagons` option affects how the octagon aperture is defined in the output files. The parameter to this option must either be `rotate` or `normal`. Normally, octagons begin at an angle of 22.5 degrees, but some Gerber viewers have a problem with that (notably CircuitMaker from LPKF). These programs expect octagons to begin at 0.0 degrees.

  The `--octagons=normal` option is the default (22.5 degrees) and need not be specified. A rotation of 0.0 degrees can be achieved by specifying `--octagons=rotate`.

--random-search
  This option is the default when only a configuration file is specified (see the documentation on Automatic Placement for more information). It indicates that a randomized search of possible job tilings is to be performed. This option does not make sense when a layout file is specified.

--full-search
  This option may be specified to indicate that all possible job tilings are to be searched (see the documentation on Automatic Placement for more information). This option does not make sense when a layout file is specified.

--rs-fsjobs=N
  This option is used with randomized search to indicate how many jobs are to undergo full search for each tiling. See the documentation on Automatic Placement for more information.

--place-file=filename
  This option performs a panel layout based upon absolute job positions in the given text file, rather than by random/full search or by a layout file. The placement file created by GerbMerge can be used as an input file to this option in order to recreate a previous layout.

--no-trim-gerber
  This option prevents GerbMerge from trying to trim all Gerber data to lie within the extents of a given job's board outline. Normally, GerbMerge will try to do so to prevent one job's Gerber data (most notably, silkscreen lines for connectors that protrude from the board) from interfering with a neighboring job on the final panel. Specify this command-line option if you do not want this trimming to occur.

--no-trim-excellon
  This option prevents GerbMerge from trying to trim all Excellon data to lie within the extents of a given job's board outline. Normally, GerbMerge will try to do so to prevent one job's drill holes from landing in the middle of a neighboring job on the final panel. Specify this command-line option if you do not want this trimming to occur.

-h, --help
  The '`-h`' or '`--help`' option prints a brief summary of available options.

-v, --version
  The '`-v`' or '`--version`' option prints the current program version and author contact information.

## Copyright & License

Copyright © 2003-2008 Andrew Sterian. All Rights Reserved. mailto: steriana@claymore.engineer.gvsu.edu

GerbMerge comes with ABSOLUTELY NO WARRANTY. This is free software licensed under the terms of the GNU General Public License. You are welcome to redistribute this software under certain conditions. For more details, see the previous link or visit The Free Software Foundation.

## To Do

1. Accept outputs from more CAD programs
2. A graphical interface for interactive placement
3. Better reporting of parse errors in the layout and configuration files
4. Implement simple primitive for panelizing a single job in an array
5. More intelligent placement algorithms, possibly based on the fabric cutting problem.
6. Accept aperture macro parameters and operators

## Credits

Thanks to Jace Browning for major contributions to this code. This help file is based on a template for the help file for mxTools by M.A. Lemburg. This software was created with VIM; thanks to the authors of this program and special thanks for the Python syntax support. Thanks to M.A. Lemburg for his mxBase package, Mike Fletcher for his SimpleParse package, and the authors of gerbv, a great Gerber file viewer for Linux, and, of course, to the Python developers and support community.

Thanks to Joe Pighetti for making me start writing this program, and to the Grand Valley State University Firefighting Robot Team for making me finish it.

Thanks to Matt Kavalauskas for identifying Eagle's annulus and thermal macros and supporting the development of the aperture macro code.

## History

Version 1.6 -- October 5, 2008

- A new configuration option was introduced (`MinimumFeatureSize`) that implements automatic feature thickening to some minimum dimension. This is intended to automatically thicken silkscreen layers.
- Negative X/Y co-ordinates in input files are now supported.
- Layout files (i.e., DEF files) now support job names that have hyphens in them, and names that start with numbers.
- Job names are case-insensitive in layout files. You should not have two job names specified in the configuration file that differ only in case.

Version 1.5 -- September 15, 2008

- Added `DrillClusterTolerance` configuration option to control drill clustering. The TOLERANCE global variable in `drillcluster.py` was removed.
- Added support for 90, 180, and 270 degree board rotations in manual layout. Automatic placement still only tries board rotations of 90 degrees.
- Fixed bug that prevented the placement file approach from working when there were rotated jobs.

Version 1.4 -- September 10, 2008

- Drills can now be optionally clustered to reduce the total number of drills in the merged job. Cluster tolerance is set by adjusting TOLERANCE in `drillcluster.py`.

Version 1.3 -- October 31, 2006

- Gerber files are now generated and represented in 2.5 format.
- Bug fix in generating scoring lines.

Version 1.2 -- September 16, 2006

- Added support for Protel-generated Gerber/Excellon files.
- Ensured Excellon tool numbers always have at least two digits (e.g., 'T01' instead of 'T1').

Version 1.1 -- November 10, 2005

- Added `ScoringFile` option.

Version 1.0 -- August 20, 2005

- The configuration file now has a `MergeOutputFiles` section allowing user-configurable output file names.
- The `OutlineLayer` config option is now called `OutlineLayerFile`.
- The `FabricationDrawing` config option is now called `FabricationDrawingFile`.
- The sample configuration files have much more documentation.
- Changed the default `XSpacing`/`YSpacing` values to 0.125".
- BUG: Unspecified cut line/crop line/etc. widths ended up being 0-mil lines instead of the default 10-mil lines.
- The default value of `ExcellonDecimals` is now 4 instead of 3.
- The internal drill location representation is now in 2.4 instead of 2.3 format.
- Aperture codes with more than 2 digits are accepted as input.
- The initial exposure-off flash command in each layer has been moved to be at a non-negative co-ordinate.
- Better documentation of configuration file format syntax.
- Fewer rotated aperture macros are generated, leading to smaller Gerber output files.
- Gerber files now only write out aperture and macro definitions actually used in that file, leading to slightly smaller Gerber output files.
- Python 2.3 is now required.
- BUG: `--place-file` did not work when job names had uppercase characters.
- Drills that occur outside of the board outline (as set by the `BoardOutline` layer in the configuration file) are deleted, unless `--no-trim-excellon` is specified.
- A new configuration option `ExcellonLeadingZeros` causes leading zeros to be written to the merged Excellon file.
- New configuration options `LeftMargin`, `TopMargin`, `RightMargin`, `BottomMargin` were introduced.
- Jobs are now trimmed to the extents of the board outline (as set by the `BoardOutline` layer in the configuration file) unless `--no-trim-gerber` is specified.

Version 0.9 -- August 12, 2005

- Added aperture macro support
- Excellon files are now generated in 2.4 format
- Job-specific `ExcellonDecimals` parameter was added

Version 0.8 -- October 16, 2004

- Added new `OutlineLayer` configuration option

Version 0.7 -- August 27, 2004

- Added support for automatic placement.
- Added support for manual placement from a text file.
- Added new `PanelWidth` and `PanelHeight` global configuration options.
- Added new `--random-search`, `--full-search`, `--place-file`, and `--rs-fsjobs` command-line options.
- Added new `Repeat` configuration option to support automatic placement.
- Every successful run of GerbMerge now writes the final job placement in a `merged.placement.txt` file.
- Fixed a bug that prevented some drills from appearing in the merged output files when a job had a tool list with different tool names but the same drill sizes.

Version 0.6 -- April 26, 2004

- Added support for the new Excellon format of Eagle version 4.11r2.
- Added support for PCB in the RS274X and Excellon parser.
- The global ToolList file is now optional. Each job can specify its own tool list, or the tool sizes can be deduced from Excellon files which have tool size information. The global ToolList option is still used to specify tool sizes for jobs that have none of the above.
- Added new `CutLineWidth` and `CropMarkWidth` options.
- Backwards-incompatibly removed the `Spacing` option and replaced it with `XSpacing` and `YSpacing`.

Version 0.5 -- March 1, 2004

- Added support for Orcad in the RS274X parser.
- Added `ExcellonDecimals` configuration file option, to support Excellon files generated by Orcad.
- The tool list file format was relaxed a bit to allow more whitespace and to support mils.

Version 0.4 -- November 26, 2003

- Fixed an error that occured when more than 99 apertures were present in the merged files. All apertures above D99 were ignored and did not appear in the merged output
- All carriage-return (0x0D) characters are stripped from input files allowing DOS-generated input files to be processed on a Unix system
- Added 7 more glyphs to the drill symbols for the fabrication drawing, now allowing up to 26 different tool symbols

Version 0.3 -- October 23, 2003

- Added support for Eagle 4.11

Version 0.2 -- May 16, 2003

- Added support for fabrication drawings

Version 0.1 -- March 4, 2003

- Initial release

© 2003-2008, Copyright by Andrew Sterian; All Rights Reserved. mailto: steriana@claymore.engineer.gvsu.edu