altium monkey v2026.11.26 · gobblerito
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:

  1. create or modify .SchDoc files
  2. add schematic primitives, ports, notes, templates, and images
  3. insert components from .SchLib
  4. iterate and normalize existing schematic objects
  5. render schematic pages to SVG
  6. 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:

python
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:

python
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:

python
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.

python
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:

python
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:

See the Schematic Rendering & Paint IR guide for full rendering workflows and legacy GOTIR migration.

Guarantees & Stability Boundaries

Examples

Start with:

  1. hello_schdoc
  2. schdoc_vertical_pin_svg
  3. schdoc_add_note
  4. schdoc_note_command
  5. schdoc_move_note
  6. schdoc_add_harness_connector
  7. schdoc_mutate_harness_connector
  8. schdoc_add_sheet_symbol
  9. schdoc_mutate_sheet_symbol
  10. schdoc_insert_dblib_style
  11. schdoc_clean
  12. schdoc_svg
  13. schdoc_apply_dynamic_template
  14. extractable_asset_inventory

See API patterns for cross-cutting mutation and ownership guidance.

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