On This Page (7)
PrjPcb
AltiumPrjPcb (altium_monkey.altium_prjpcb) is the public container for Altium .PrjPcb project files. Use it to inspect or update project documents, parameters, variants, netlist/hierarchy settings, class-generation policies, and associated OutJobs.
Use it when you need to:
- read or update schematic, PCB, library, device-sheet, and OutJob document references (
get_schdoc_paths,get_reachable_schdoc_paths,get_pcbdoc_paths,get_outjob_paths) - get, set, or delete project parameters (
[ParameterN]) cleanly without affecting variant parameters ([ParameterV_N]) - inspect parsed variants, strict admitted variation rows (
admitted_variations,admitted_DNP), and variant-level[ParameterV_N]parameters - inspect
net_identifier_scope,netlist_options, and project/document[PrjClassGen]ECO class-generation policies - create a minimal
.PrjPcbviaAltiumPrjPcb.create_minimal(...)orAltiumPrjPcbBuilder - resolve and run a project-associated OutJob via
prj.outjob().run(...)
Import note:
AltiumPrjPcb,AltiumPrjPcbOutJob,AltiumPrjPcbClassGenerationOptions, andAltiumPrjPcbDocumentClassGenerationOptionsare imported fromaltium_monkey.altium_prjpcb(AltiumPrjPcb("project.PrjPcb"); there is no.from_file(...)classmethod).AltiumPrjPcbBuilderis exported at top level fromaltium_monkey.
Project Parameters
Project parameters belong in the .PrjPcb (as [ParameterN] sections), not in schematic documents. Title blocks, dynamic templates, and PCB special strings resolve expressions such as =PROJECT_TITLE, =PCB_PART_NUMBER, or =VariantName from these entries.
from altium_monkey.altium_prjpcb import AltiumPrjPcb
prj = AltiumPrjPcb("project.PrjPcb")
prj.set_parameter("PROJECT_TITLE", "Example Project")
prj.set_parameters({"PCB_PART_NUMBER": "WN-001", "PCB_CODENAME": "demo"})
value = prj.get_parameter("PROJECT_TITLE")
prj.delete_parameter("OLD_PARAMETER")
prj.save("project.PrjPcb")Parameter rules (matching Altium Designer):
- Project vs. variant isolation: Only
[ParameterN]sections (no_in the section header) with contiguousName=/Value=lines count as project parameters. Variant[ParameterV_N]sections are excluded fromprj.parametersand untouched byset_parameter(...)/delete_parameter(...). *reads as empty: A stored*parameter value reads as"".- Duplicate resolution: Duplicate parameter names match case-insensitively (Altium's name key), preserving the first spelling with last value wins.
set_parameter(...)anddelete_parameter(...)update or remove every case-matching project parameter section.
Variants
AltiumPrjPcb.variants parses [ProjectVariantN] sections (disambiguating duplicate Description names with _1, _2, …) and exposes both the raw records and strictly admitted rows:
from altium_monkey.altium_prjpcb import AltiumPrjPcb
prj = AltiumPrjPcb("project.PrjPcb")
for name, info in prj.variants.items():
print(
name,
"admitted DNP:", info["admitted_DNP"],
"variant params:", info["parameters"],
)Each variant dictionary includes:
admitted_variations&admitted_DNP: Variation rows (Variation1..N) that pass Altium's strict admission check — at least four ordered fields (Designator=,UniqueId=,Kind=,AlternatePart=) with a non-blankUniqueId(Kind == "1"marks Not Fitted / DNP). Malformed or blank-UID rows are excluded from compilation and emit compile warnings (variation_row_malformed,variation_row_without_unique_id).variations&DNP: Raw parsed variation rows retained for inspection.parameters:list[dict[str, str]]({"Name": ..., "Value": ...}) parsed from the[ParameterV_N]sections following[ProjectVariantN], with values kept as written.- Metadata:
param_variations,param_overrides,unique_id,allow_fabrication, andoverwrite_schematic_symbol.
AltiumDesign, AltiumCompilation, and Fab consume admitted_variations: PCB-backed BOM and Pick & Place match component Not-Fitted status by UniqueId (while Pick & Place applies parameter variations by designator and PCB BOM applies them by UniqueId). Alternate fitted component rows remain in raw metadata and are not applied as schematic symbol replacements.
To create or select an empty variant header on a project:
prj.add_variant("A", current=True)
assert prj.get_current_variant() == "A"add_variant(...) creates or updates an empty project variant header; it does not author component-level variation rows.
Documents, Reachability & Builders
- Reading document paths:
prj.get_schdoc_paths()/prj.get_pcbdoc_paths()/prj.get_outjob_paths()return project-relative document paths from contiguous[Document1..N]entries.prj.get_reachable_schdoc_paths()includes compile-participating sheets past numbering gaps and managed[DeviceSheetN]entries.prj.get_saved_structure_top_level_schdoc_name()andprj.get_saved_structure_schdoc_paths()inspect saved hierarchy hints.
- Mutating document membership:
prj.add_document(path, unique_id=None)normalizes and appends a[DocumentN]entry (raisingValueErroron duplicate paths; it does not validate or infer file types from the suffix).prj.remove_all_documents()andprj.set_documents_from_directory(...)rebuild document membership from a project directory.AltiumPrjPcb.create_minimal(name="project")creates a fresh in-memory project.
- Minimal new project builder (
AltiumPrjPcbBuilder): Exported at top level fromaltium_monkeywith suffix-checked helpers (add_schdoc,add_pcbdoc,add_schlib,add_pcblib,add_outjob) for generating clean minimal.PrjPcbfiles. - Board → Project auto-discovery (
find_board_project):from altium_monkey.fab import find_board_projectwalks parent folders upward, opens candidate.PrjPcbfiles viaAltiumPrjPcb, and finds the project listing a given.PcbDoc(used automatically byboard.fab()and exposed onfab.project). NewIndexingOfSheetSymbolsonsave(): Newly created in-memory projects materializeNewIndexingOfSheetSymbols=1onsave()if absent; loaded projects materialize0if absent so existing hierarchy semantics stay stable.
Net Identifier Scope, Netlist Options & Class Generation
prj.net_identifier_scopereturns aNetIdentifierScope(IntEnum, preserving unknown raw integers cleanly) andprj.netlist_optionsexposes parsed netlist/compiler configuration flags.prj.class_generation_optionsexposes the project-wide[PrjClassGen]policy that controls user-defined and schematic class transfer during Altium compile/ECO workflows (for example,net_class_manual_enabled=Truetransfers directiveClassNameandDifferentialPairClassNamevalues into PCBClasses6/Data):
from altium_monkey.altium_prjpcb import (
AltiumPrjPcb,
AltiumPrjPcbClassGenerationOptions,
)
prj = AltiumPrjPcb("project.PrjPcb")
options = prj.class_generation_options
prj.set_class_generation_options(
AltiumPrjPcbClassGenerationOptions(
net_class_manual_enabled=True,
)
)
prj.save("project.PrjPcb")Per-document class-generation policy is available through get_document_class_generation_options(...) and set_document_class_generation_options(...) (accepting a zero-based index, project-relative path, or filename).
OutJobs
Resolve a project-associated .OutJob with prj.outjob(name=None) (defaulting to reference_gen.OutJob or the sole sibling .OutJob) or the dynamic <stem>_outjob attribute (such as prj.reference_gen_outjob), and invoke .run(...) (preferred_version defaults to None, using ALTIUM_PREFERRED_VERSION or the newest installed Altium Designer):
from altium_monkey.altium_prjpcb import AltiumPrjPcb
prj = AltiumPrjPcb("working-copy/project.PrjPcb")
result = prj.outjob().run(
timeout_seconds=300,
stage_outjob_copy=False,
)For cross-platform Gerber, NC drill, IPC-2581B, Pick & Place, BOM, and SVG generation without desktop Altium, use board.fab() (Fab & FabView). For desktop X2.EXE OutJob automation rules — including why PDF/Publish and printer containers are not reliably supported — see Launcher & OutJobs and its Known Limitations.
Guarantees & Stability Boundaries
- Encoding: Reads honor UTF-8/UTF-16 BOMs and fall back to Windows-1252 without a BOM;
save(...)writes UTF-8 with BOM and preserves unknown sections and keys. Newly constructed in-memory projects materializeNewIndexingOfSheetSymbols=1on save, whereas loaded projects materializeNewIndexingOfSheetSymbols=0when absent so existing indexing does not shift. - Parameter & variant rules:
[ParameterV_N]variant sections are strictly excluded from project parameters ([ParameterN]). Stored*project parameter values read as"", and duplicate names resolve case-insensitively (first spelling kept, last value wins). Strictadmitted_variations/admitted_DNPrequire all four ordered fields (Designator=,UniqueId=,Kind=,AlternatePart=) with a non-blankUniqueId. - Cross-platform document paths: Windows-style separators resolve cleanly on Windows, macOS, Linux, and WSL while preserving Altium's stored separator form on save.
DocumentUniqueIdon[DocumentN]/[DeviceSheetN]takes precedence over sheet-headerUniqueIDduring compilation.
Examples
Start with:
prjpcb_variants_and_class_generationprjpcb_make_projectoutjob_runnerschdoc_apply_dynamic_templatehello_altium_design
See AltiumDesign & Compiled Design for project-level compilation and JSON contracts.