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
- Normal SVG output includes a root
viewBox. include_view_box=Falseomits only the rootviewBoxattribute.- Omitting the
viewBoxdoes not change geometry, metadata, filenames, layer keys, or element identifiers. - SVG DOM
idvalues are render-output identifiers. Downstream tools should prefer documenteddata-*metadata when semantic identity is needed.
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:
components[].svg_idpoints to the component SVG group id, normally the component record UniqueID.- optional
indexes.svg_to_componentmaps component SVG ids back to designators when indexes are requested. - for repeated sheets and instantiated channels,
compiled_schematic_graph.graphical_artifact_links[]disambiguates a logical element id with its canonicalpage_occurrence_refand semantic target. nets[].graphicalgroups related schematic SVG ids by record type:wires,junctions,labels,power_ports,ports,sheet_entries, andpins.nets[].graphical.pins[]contains{designator, pin, svg_id}objects so a viewer can highlight the actual pin SVG element.nets[].endpoints[]provides semantic trace endpoints.element_idis the current SVG render target, whileobject_idis the source electrical object id when it differs from the rendered element. Endpoint connection points use source schematic coordinates, not SVG coordinates.
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:
{"kind": "pad_labels"}: each copper land's pad designator (itspin) at the centre of the box of its pad's lands on that key, sized to fit inside the box less a tenth each side (at most 0.72 of that height, each glyph 0.62 of the size wide).board.svglabels each pad once, from the last copper key drawn that has its lands; a layer image labels its own key's pads.{"kind": "origin_marker"}: a circle of 0.6 mm and a cross of 0.81 mm arms about the board's user origin (the view'sboard().origin), stroked 0.08 mm; its box joins the image's frame. For a footprint this is the footprint origin, (0, 0).
<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:
- emitted view information
- included layer ids
- layer token mappings
- net and net-class summaries
- component placement summaries
- board-outline and drill relationships
The payload is embedded as escaped JSON in:
<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:
schema: schema id, currentlyaltium_monkey.pcb.svg.enrichment.a0source: source-document context, includingpcbdoc_filewhen knownboard: board centroid information in mils when knownview: emitted view metadatalayers: layer mapslookup: net/component lookup tablescomponents: component placement summaries used by SVG viewers
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:
kind:board,layer_set, orboard_outline_only, derived from emitted layer groups and board-outline geometryincluded_layer_ids: sorted renderer layer ids forid="layer-*"groups actually emitted in this SVG. These are legacy source ids for native legacy layers and renderer-assigned ids for derived layers such asDRILLS. V7-only native layers do not appear in this legacy-id list; use the elements'data-layer-token/data-layer-v7-saved-idattributes for those identities. Requested layers filtered out as empty are not listed unlessshow_empty_layers=Truecauses an empty group to be emitted.includes_board_outline: true only when board-outline geometry is actually emitted
The layers object is the discovery and lookup registry for the rendered board context:
all_layer_ids: known renderer layer ids for the rendered board context; entries can exist even when the current SVG view does not emit that layer group. These are legacy source ids for native legacy layers and renderer-assigned ids for derived layers, not serialized V7 saved layer ids.layer_id_to_key: stable short keys such asL1,L32, andDRILLSlayer_id_to_name: stable tokens such asTOP,BOTTOM, andDRILLS
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.