rs274x — RS-274X file handling

The RS-274X (Gerber) format is the most common format for exporting PCB artwork. The Specification is published by Ucamco and is available here. The rs274x submodule implements calsses to read and write RS-274X files without having to know the precise details of the format.

The rs274x submodule’s read() function serves as a simple interface for parsing gerber files. The GerberFile class stores all the information contained in a gerber file allowing the file to be analyzed, modified, and updated. The GerberParser class is used in the background for parsing RS-274X files.

Functions

The rs274x module defines the following functions:

read(filename)

Read data from filename and return a GerberFile

Parameters:

filename : string

Filename of file to parse

Returns:

file : gerber.rs274x.GerberFile

A GerberFile created from the specified file.

Classes

The rs274x module defines the following classes:

class GerberFile(statements, settings, primitives, apertures, filename=None)

A class representing a single gerber file

The GerberFile class represents a single gerber file.

Parameters:

statements : list

list of gerber file statements

settings : dict

Dictionary of gerber file settings

filename : string

Filename of the source gerber file

Attributes

comments: list of strings List of comments contained in the gerber file.
size (tuple, (<float>, <float>)) Size in [self.units] of the layer described by the gerber file.
bounds: tuple, ((<float>, <float>), (<float>, <float>)) boundaries of the layer described by the gerber file. bounds is stored as ((min x, max x), (min y, max y))

Methods

offset
render
to_inch
to_metric
write
write(filename, settings=None)

Write data out to a gerber file.

class GerberParser

GerberParser

Methods

dump_json
dump_str
evaluate
parse
parse_raw
evaluate(stmt)

Evaluate Gerber statement and update image accordingly.

This method is called once for each statement in the file as it is parsed.

Parameters:

statement : Statement

Gerber/Excellon statement to evaluate.