On This Page (10)
SchDoc
AltiumSchDoc is the public container for schematic documents. It is the most complete document object model in the current release.
Use it when you need to:
- create or modify
.SchDocfiles - add schematic primitives, ports, notes, templates, and images
- insert components from
.SchLib - iterate and normalize existing schematic objects
- render schematic pages to SVG
- inventory placed symbols and extract one selected or complete
.SchLib
Object Model
AltiumSchDoc owns a single ObjectCollection. Typed properties such as schdoc.notes, schdoc.ports, schdoc.net_labels, schdoc.components, schdoc.sheet_symbols, and schdoc.harness_connectors are live filtered views over that collection. schdoc.objects and schdoc.all_objects are also read-only live views.
Use these views for query and traversal. Do not append to a view or assign all_objects. Change membership through the document:
note = make_sch_note(...)
schdoc.add_object(note)
for note in schdoc.notes:
note.font = SchFontSpec(name="Courier New", size=10)
schdoc.remove_object(note)
schdoc.save("updated.SchDoc")The document resolves IndexInSheet, owner indexes, font indexes, and related serialization details when objects are added, removed, and saved.
Units
Public SchDoc authoring APIs use mils. Prefer SchPointMils, SchRectMils, SchFontSpec, ColorValue, and public enums instead of raw integer fields.
Low-level record fields may expose native Altium storage units. Use those fields only when preserving parsed data or when no high-level property exists yet.
Ownership
Some schematic records are invalid as top-level objects. Add them through their owner object so ownership and indexes stay valid.
Harness entries and harness type labels belong to harness connectors.
Sheet entries, sheet-name labels, and file-name labels belong to sheet symbols.
Component pins, designators, parameters, and implementation records belong to components.
Use schdoc.add_component_from_library(...) for normal component insertion from SchLib.
When placing a SchLib symbol, add_component_from_library(...) preserves the symbol's child record order. This keeps intentional schematic draw order intact for cases where pins, rounded rectangles, designators, and other visible child records overlap.
Symbol Extraction
Use AltiumSchDoc.extract_schlib(...) when a caller needs an in-memory AltiumSchLib from the placed component symbols in a schematic.
Use AltiumSchDoc.extract_symbols(...) when writing split or combined .SchLib files:
schdoc = AltiumSchDoc("input.SchDoc")
schlib = schdoc.extract_schlib()
schdoc.extract_symbols(
"output_symbols",
split_schlibs=True,
combined_schlib=False,
)Both paths share the same extraction model. Symbols are grouped by design item, component-owned child records are transformed back into symbol coordinates, and implementation/model records can be preserved with strip_implementations=False. The default file-writing behavior remains compatible with earlier releases.
Templates
Use clear_template(), apply_template(...), and extract_template(...) for schematic title blocks and border graphics stored as Altium .SchDot templates.
By default, apply_template(...) applies template-owned drawing objects, embedded images, fonts, missing template parameters, and template metadata. It does not change the target sheet size or page setup unless requested.
If the .SchDot should also control the target page setup, pass apply_visual_sheet_settings=True:
schdoc.apply_template(
"title_block.SchDot",
template_filename="title_block.SchDot",
apply_visual_sheet_settings=True,
)That option copies visual sheet context such as sheet style, custom sheet dimensions, border and reference-zone settings, display unit, grid settings, sheet colors, sheet-number spacing, and the sheet system font. It does not copy template identity, vault/release GUIDs, sheet number, or project/page parameters.
Embedded Images
AltiumSchDoc preserves embedded IMAGE payloads in the schematic Storage stream. When Altium stores an image as a BMP preview plus a native payload such as TdxPNGImage, SVG rendering and extract_embedded_images(...) prefer the native payload so PNG alpha is preserved. Plain 24-bit and 32-bit BMP payloads are opaque, as Altium draws them: the fourth byte of a 32-bit BMP pixel is reserved, not alpha.
The Storage reader also accepts Altium-tolerated legacy streams whose physical rows extend beyond the effective declared count. Only rows selected by the managed header are interpreted; selected framing, compression, and payloads remain strictly validated and charged to decompression limits. If selected rows repeat a case-insensitive name, image lookup retains the first row. When the effective Storage count, duplicate names, or header termination needs repair, saving regenerates a canonical count and header from the selected live entries.
Use schdoc.extract_embedded_images(output_dir) when writing embedded images as standalone files. Direct image.image_data access is a preservation API: it returns the raw Storage payload and may include Altium wrapper bytes before the native image. Code that needs image files should not hash or write image.image_data directly unless it intentionally wants the exact stored payload.
Extractable Assets
AltiumSchDoc.asset_inventory() lists placed schematic symbols with typed SchSymbolAssetDetails. Use the returned AltiumAssetRef with extract_asset(...) to extract one selected symbol as a single-symbol AltiumSchLib.
inventory = schdoc.asset_inventory()
symbol = next(
(item for item in inventory.by_kind("sch_symbol") if item.can_extract),
None,
)
if symbol is None:
raise RuntimeError("no extractable schematic symbol found")
extracted = schdoc.extract_asset(symbol.ref)
extracted.schlib.save("selected_symbol.SchLib")For the shared reference and JSON contract, see Asset & Library Extraction.
SVG & Paint IR Rendering
AltiumSchDoc.to_svg(...), to_paint_ir(...), and to_paint_png(...) render schematics through Schematic Paint IR A0:
from altium_monkey import AltiumSchDoc, SchPaintSvgOptions, SchPaintView
schdoc = AltiumSchDoc("sheet.SchDoc")
# Standard SVG (text elements, static view, root viewBox included)
svg = schdoc.to_svg(options=SchPaintSvgOptions())
# Self-contained SVG with outlined text (no viewer font dependency)
outlined_svg = schdoc.to_svg(options=SchPaintSvgOptions(text_mode="paths"))
# Editor presentation with grid/hotspots or Paint IR A0 JSON export
editor_view = SchPaintView.editor()
scene = schdoc.to_paint_ir(view=editor_view)
scene.write_json("sheet.paint-ir.json")Key rules:
- Normal SVG output includes a root
viewBox; setinclude_view_box=Falseto omit only that attribute.scale=1.0is currently required for SchDoc SVG. - The default view is
SchPaintView.static_scene()(no editor grid or pin hotspots). Passview=SchPaintView.editor()plusSchPaintSvgOptions(include_editor_grid=True, include_editor_hotspots=True)to include editor adornments in SVG. - Font resolution prefers installed or
ALTIUM_FONT_DIRSfonts and falls back to bundled Arimo, Tinos, and Cousine faces.embed_bundled_fallback_fonts=Trueis not supported and raisesSchPaintRenderError; usetext_mode="paths"for portable self-contained SVGs. - Public
to_svg(...)retains supported drawing when a reviewed unsupported appearance is encountered, logging diagnostics rather than aborting the sheet. Useto_paint_ir(...)when strict A0 validation is required.
See the Schematic Rendering & Paint IR guide for full rendering workflows and legacy GOTIR migration.
Guarantees & Stability Boundaries
- Preservation: Unknown or unsupported records and properties are preserved during normal read/write round trips.
- Netlist hotspot projection: Sheet-entry and harness-entry connectivity composes
DistanceFromTop * 10 + DistanceFromTop_Frac1 / 100000(rounded half-away-from-zero to native 10-mil schematic units) before endpoint matching, while SVG geometry and low-level record round-tripping preserve the source fields independently. - Embedded Storage compatibility: Root
Storagereads use bounded declared-prefix semantics; stale effective counts, missing header terminators, or case-insensitive duplicate names are regenerated canonically on save.
Examples
Start with:
hello_schdocschdoc_vertical_pin_svgschdoc_add_noteschdoc_note_commandschdoc_move_noteschdoc_add_harness_connectorschdoc_mutate_harness_connectorschdoc_add_sheet_symbolschdoc_mutate_sheet_symbolschdoc_insert_dblib_styleschdoc_cleanschdoc_svgschdoc_apply_dynamic_templateextractable_asset_inventory
See API patterns for cross-cutting mutation and ownership guidance.