altium monkey v2026.11.26 · gobblerito
On This Page (6)

SVG Contract

altium-monkey emits SVG for schematic documents, schematic library symbols, PCB documents, and PCB library footprints. SVG is a review and integration format, not a full replacement for the source Altium files.

Common Rules

Schematic SVG

Canonical SchDoc, SchLib and physical-page SVG methods draw directly through schematic Paint IR A0. Source operands use mils; the SVG adapter performs output scaling and Y-axis conversion. SchPaintSvgOptions selects presentation size, viewport, text/path output, optional fallback-font embedding and metadata. The default includes a root viewBox and filters editor grid/hotspot adornments; SchDoc SVG also defaults to static planning. Doc and physical Paint IR command comparisons can select SchPaintView.editor(). SchLib comparisons select their explicit symbol/part/display-mode source snapshot without a view keyword. These command comparisons are separate from SVG presentation.

Persisted source UIDs may identify source groups. SchLib source-ordinal groups use the governed collision-resolved identifiers. The default A0 adapter does not promise the old root data-doc-id/data-doc-ver attributes, physical page attributes or every generated legacy helper wrapper. include_group_metadata exposes occurrence, role and paint-pass attributes; wrap_components exposes component wrappers. None converts opaque Paint IR source keys into graph IDs.

Public SVG recovers only reviewed unsupported-appearance branches, retaining available content with exact logged diagnostics and an incomplete-preview marker. Strict Paint IR remains independent; partial SVG is not an Altium reference pass. Validation, limits, invariants and programming errors remain strict.

The authoritative relationship sidecar remains the AltiumDesign.to_json(...) and Netlist.to_json(...) payload:

For schematic visualization, use the SVG as the drawing surface and the design or netlist JSON as the semantic lookup table. Do not infer electrical meaning from rendered text strings or group nesting alone.

Physical rendering uses AltiumDesign.to_physical_svg(page_occurrence_ref, options=...) and the existing compiled physical designator selection. Strict JSON consumers use to_physical_paint_ir(page_occurrence_ref) independently. Consumers retain the canonical page occurrence and sch.dwg_scene graphical-link scope in the semantic sidecar; application enrichment is separate from the core SVG adapter. get_physical_document_id_for_page(...) transports the existing selected physical-document ID without a new semantic join or schema.

Paint IR image resources carry normalized PNG bytes and declared source-pixel crop/destination operands. The SVG adapter preserves resource bytes and applies that crop. Font measurement uses the package font resolver. SchPaintSvgOptions(embed_bundled_fallback_fonts=True) is not supported by the Paint IR A0 SVG adapter and raises SchPaintRenderError; use SchPaintSvgOptions(text_mode="paths") when a self-contained SVG must render identically without host fonts.

PCB SVG

PcbDoc and PcbLib images are lowerings of the board's or the footprint's Fab view through the Fab SVG writer (altium_monkey.fab.svg): Fab.to_svg and Fab.to_layer_svgs, their board shortcuts AltiumPcbDoc.to_svg and to_layer_svgs (see the PcbDoc contract), and AltiumPcbFootprint.to_svg and to_layer_svgs (below). Each returns a FabOutput: to_svg one file, board.svg; to_layer_svgs one <key>.svg per layer key of the view, its dielectrics aside, and DRILLS.svg, the holes, every image in one frame so the images overlay.

Coordinates are millimetres with +Y down: a board point (x, y) in nanometres, +Y up, is written at ((x - ox) / 1000000, (oy - y) / 1000000). The root states the unit and the origin (data-unit-nm, data-origin-nm), so a reader recovers board coordinates, and every coordinate is rounded once to 1 nm. The viewBox is the frame: the profile's box when the view has a profile, else the box of what the images draw, the origin marker's box joined where it is asked for. width and height are the frame in millimetres times the scale option.

A layer image names its layer on the root: data-layer (Altium's name for it), data-role, data-side and data-polarity (a plane's negative film is negative). board.svg holds one group per key in paint order, <g data-key="TOP" data-layer="Top Layer" data-role="conductor" data-side="top" data-polarity="positive">: by default the copper, mask, paste and overlay keys bottom side first, so the top side shows on top, a plane as its copper, then the mechanical, keep-out and profile keys, then the holes knocked out in white (data-layer="Holes" data-role="holes"). The layers option names the keys and their order (PROFILE the outline, DRILLS the holes, plus any of the 17 on-demand virtual layer keys: CUTOUTS, PIN1_TOP/PIN1_BOTTOM, DIODES_TOP/DIODES_BOTTOM, CAPACITORS_TOP/CAPACITORS_BOTTOM, INDUCTORS_TOP/INDUCTORS_BOTTOM, RESISTORS_TOP/RESISTORS_BOTTOM, ASSEMBLY_OUTLINES_TOP/ASSEMBLY_OUTLINES_BOTTOM, ASSEMBLY_DESIGNATORS_TOP/ASSEMBLY_DESIGNATORS_BOTTOM, and PAD_LABELS_TOP/PAD_LABELS_BOTTOM), and layer_colours their paint; a key not given takes its layer's colour. Shaded virtual layers apply per-item VirtualItemStyle (fill, stroke, contrast halo_color/halo_width_nm, and opacity) configured via virtual_options (including stroke/TrueType text and geometric knockout=True pad labels on both .PcbDoc and .PcbLib footprint views).

Items are drawn as the Gerber lowering draws them: a disk as a <circle>; an annulus, a rectangle, a capsule and an outline as filled paths, each arc an A command of at most a quarter turn, holes as further subpaths under fill-rule="evenodd"; a round-capped stroke as a stroked path. With the metadata option each element names its item: data-kind, data-id (its record, such as track.4), data-net and data-source. mirror mirrors each image left to right about its frame's centre (a bottom view), clip_to_outline clips each key to the profile less its cutouts, and clip_holes knocks the holes their drill pairs span out of each copper key.

PCB Review Overlays

Footprint images come from the footprint's Fab view, as board images come from the board's: PcbFootprint.to_svg(**options) and PcbFootprint.to_layer_svgs(**options) take the Fab SVG options and parameters and return a FabOutput (board.svg; <key>.svg and DRILLS.svg), drawn about the footprint origin, a pad's Rule-mode solder mask and paste expansion drawn as zero, as the PcbLib editor shows it. A footprint has no board outline, so its images are framed by what they draw, every layer image in one frame. Whole-board images: PcbDoc.to_svg(**options) and PcbDoc.to_layer_svgs(**options) (see the PcbDoc contract).

Review overlays are the Fab SVG option annotations, a list of kinds, none by default, each drawn once over an image's layers in the order given:

xml
<g data-annotation="pad_labels" fill="#111111" stroke="none"
   font-family="monospace" text-anchor="middle" dominant-baseline="central">
  <text x="-1.27" y="0" font-size="0.585216">1</text>
</g>
<g data-annotation="origin_marker" fill="none" stroke="#00AEEF"
   stroke-width="0.08" stroke-linecap="round">
  <circle cx="0" cy="0" r="0.6"/>
  <path d="M -0.81 0 L 0.81 0 M 0 0.81 L 0 -0.81"/>
</g>

With metadata, each label names its pad (data-kind="pad_label", data-id the pad's record). A mirrored image places both at their mirrored places and keeps the labels readable. Naming a kind twice raises ValueError.

PCB Enrichment Metadata

Altium Cruncher's pcb-svg and toon embed this metadata in each document when global.include_metadata is on: the root SVG and the embedded payload use schema id altium_monkey.pcb.svg.enrichment.a0.

The PCB enrichment payload records document-level context such as:

The payload is embedded as escaped JSON in:

xml
<metadata id="pcb-enrichment-a0" data-schema="altium_monkey.pcb.svg.enrichment.a0">
  ...
</metadata>

The metadata element id is a DOM lookup anchor. The data-schema attribute and JSON schema field are the payload contract identifiers.

At the top level, the payload has these fields:

The view object describes emitted SVG structure, not merely requested render options. Use these fields when a consumer needs to know what the current SVG artifact actually contains:

The layers object is the discovery and lookup registry for the rendered board context:

Use layers.all_layer_ids for legacy-id and derived-id compatibility, and view.included_layer_ids for the legacy or derived layer groups present in the current SVG.

The schema contract pages contain the machine-readable payload shape. The SVG contract here documents how that payload relates to the rendered SVG elements.

Validation

The SVG contract is protected by targeted unit tests, public example tests, representative SVG comparisons, and release validation. The release checks also verify that these contract docs stay synchronized with the published docs.

altium-monkey v2026.11.26 · gobblerito·Docs updated 2026.11.29 17:55 UTC (0665053)