On This Page (8)
Gerber Contract
altium-monkey writes Gerber files from the board's Fab view: board.fab(...).to_gerbers(...) or the one-call shortcut board.to_gerbers(...). Output conforms to the Ucamco Gerber Layer Format Specification 2026.05 (section numbers below refer to that specification).
The Gerber writer only lowers the normalized FabView: it does not reinterpret board records. to_gerbers() draws the board view once per file set and writes each layer, pad master, drill guide, drill drawing, and PROFILE film from it. On manufacturing layers (copper, solder mask, paste, legend, profile, drill), artwork matches Altium's Gerber output except where Altium's form is deprecated or breaks the specification. See Matching Altium's form for comparison options.
Defaults
- Units and grid: millimetres,
%FSLAX46Y46*%(absolute coordinates, leading zeros omitted, 4 integer and 6 decimal digits — a 1 nm grid). No deprecatedG70/G71commands. - Coordinate range: Gerber coordinates are 32-bit integers (section 3.4.1), so at 6 decimals no point exceeds
±2147.483647 mm. Any object extending past that range is omitted and recorded asgerber_coordinate_out_of_rangein the output diagnostics while the rest of the layer is still written (AOD-005). - Gerber X2 attributes: enabled by default (
x2_attributes=True). Attributes label the image without altering geometry (section 5.1). - Copper flashes: every pad and via land is flashed, and every flash is a pad (section 6.4); see Pad forms.
- No zero-size features: zero-length strokes are emitted as disks of their width (AOD-001); features that round to zero on the output grid are omitted with diagnostics.
Matching Altium's Form
Use these options only when comparing output directly against Altium Designer's Gerber files (the defaults are recommended for fabrication; fewer than 6 decimals is deprecated):
| Option | Python keyword | Effect |
|---|---|---|
| Plain Gerber (X1) | x2_attributes=False | Emit no X2 attributes (AOD-004) |
| Altium's grid | decimal_digits=4 | %FSLAX44Y44*% (100 nm grid; deprecated per section 8.2.1.3) |
| Altium's missing dots | degenerate_strokes="omit" | Omit zero-length strokes (AOD-001) |
File Attributes
Each Gerber header carries %TF...*% file attributes:
| Attribute | Value |
|---|---|
.FileFunction | Derived from layer role, side, and physical copper index: Copper,L<n>,Top|Inr|Bot (,Plane on planes), Soldermask,Top|Bot, Paste,Top|Bot, Legend,Top|Bot, Pads,Top|Bot, Drillmap, Profile,NP, OtherDrawing,<layer name>, or Other,<layer name>. Copper layers without a copper_index emit gerber_file_function_unknown. |
.FilePolarity | Positive; Negative for solder mask films (showing openings) and negative plane films. |
.SameCoordinates | One shared GUID per to_gerbers() call unless overridden via same_coordinates. |
.GenerationSoftware | Wavenumber,altium-monkey,<version> using altium_monkey.__version__. |
.CreationDate | ISO 8601 UTC timestamp (or explicit creation_date with timezone), shared across all files in the set. |
Object Attributes
| Attribute | Applied to |
|---|---|
.AperFunction | Copper pads by role (SMDPad,CuDef, OtherPad,InnerSMD, ComponentPad, WasherPad, ViaPad, OtherPad,Unknown); plane antipads (AntiPad) and thermal reliefs (ThermalReliefPad); copper text (NonConductor); other copper (Conductor); mask/paste/legend (Material); profile (Profile). |
.N | Every copper object: net name (empty for unassigned). |
.P | Outer copper pad lands belonging to a component: <designator>,<pin>. |
.C | Every component land on any layer: component designator. |
Field values are escaped per section 3.4.3 (\uXXXX for delimiters, escape characters, and non-ASCII characters) so files remain pure ASCII. Object attributes are cleared with %TD<name>*% except .C, where %TD*% clears the dictionary before re-applying retained attributes for strict Ucamco parser compatibility (section 3.5).
Pad Forms
On copper and pad-master films, every pad or via land is a single flash. Aperture macros are preferred over block apertures (AB) for broad CAM compatibility:
| Land shape | Written as |
|---|---|
| Round | Circle aperture C |
| Round with round hole (annulus) | Circle aperture C with hole |
| Axis-aligned rectangle | Rectangle aperture R |
| Axis-aligned capsule (oval) | Obround aperture O |
| Rotated rectangle or polygon (≤ 5,000 vertices) | Aperture macro of outline primitives (code 4), holes with exposure off |
| Rounded rectangle, rotated capsule, convex equal-radius polygon | Exact aperture macro: corner circles (code 1), edge vector lines (code 20), and centre outline (code 4) |
| Custom pad with arcs, or polygon > 5,000 vertices | Block aperture (AB) holding the pad's region |
Non-pad copper (apart from plane antipad/relief flashes) is drawn with regions or strokes. Solder mask, paste, and legend openings are flashed when round or rectangular.
Regions & Contour Hygiene
Every region exterior is emitted as a spec-compliant simple contour (section 4.10.3):
- Horizontal cut-ins: each hole is joined to its exterior from the hole's rightmost point straight along
+xto the nearest contour boundary. - Pre-bridged rings & spikes: rings saved with bridges to holes/islands or zero-width spikes are split into separate loops first, then rejoined cleanly.
- Self-crossing contours: figure-eights and self-intersecting teardrops are split at crossings into simple loops filled by non-zero winding (AOD-059).
- Standalone islands: loops outside any exterior are emitted as independent contours rather than bridged diagonally.
- Sub-100 nm spike/sliver removal: points within 100 nm of their predecessor or hairpins narrower than 100 nm are pruned so no degenerate zero-length or non-horizontal coincident cut-in segments are emitted (AOD-036).
Virtual Layers & Custom Extensions
to_gerbers() also supports selective film toggles (keepout, profile, pad_masters, drill_guide, drill_drawing, mechanical_layers), dual-key custom extensions (accepting either canonical FabView layer keys like "TOP", "PROFILE", "CUTOUTS" or Altium default extensions like "GTL", "GM", "GCU"), profile_cutouts=True (drawing hatched "CUTOUT" callouts on .GM), and all 17 board-derived virtual_layers (.GCU, .GP1T/.GP1B, .GDT/.GDB, .GCT/.GCB, .GLT/.GLB, .GRT/.GRB, .GAT/.GAB, .GADT/.GADB, .GPLT/.GPLB). All virtual layers lower as monochrome positive Gerber geometry with %TF.FileFunction,OtherDrawing,<layer name>*% (e.g., OtherDrawing,Top Component Outlines, OtherDrawing,Top Component Designators). See Virtual Fab Layers for the full option contract.
Validation
Generated Gerber files are verified against a strict Ucamco 2026.05 grammar checker, read back against the board's FabView within 100 nm, and compared against Altium Designer reference captures across synthesized and real-world boards.