On This Page (4)
Examples Showcase / draftsman_netclass_autodoc
Generate Draftsman net-class highlight pages
Read JSON configs for Bunny Brain, RT Super C1, and loz-old-man, synthesize experimental board-assembly-view Draftsman pages with highlighted routed classes, and write per-project manifests.
Experimental JSON-driven sample for generated Draftsman controlled-impedance artwork pages.
The sample reads one or more config files, selects PCB geometry by net class, differential-pair class, differential-pair name, or scalar net name, and emits one Draftsman document per configured group. Each group page tiles all selected routed-layer views onto one ANSI B sheet by default and can carry group-specific notes and colors.
Run
uv run python examples\draftsman_netclass_autodoc\draftsman_netclass_autodoc.pyThe default run processes:
configs/bunny_brain.jsonconfigs/rt_super_c1.jsonconfigs/loz_old_man.json
Outputs are written under:
examples/draftsman_netclass_autodoc/outputEach config gets its own output folder, for example:
output/bunny_brain
output/rt_super_c1
output/loz_old_manAn explicit config can be supplied with:
uv run python examples\draftsman_netclass_autodoc\draftsman_netclass_autodoc.py --config path\to\config.json--config can be passed more than once.
Config Shape
Each config has a project, default sheet/scale settings, global colors, and a groups array. A group supports these selectors:
net_classesdifferential_pair_classesdifferential_pairsnets
Groups can override highlight_color, view_scale, target_fill_ratio, tile_gap_x_mm, tile_gap_y_mm, auto_fit_scale, minimum_routing_length_mils, connected_highlight_filter, and bucket colors through style. notes are rendered below the upper-left page title and are excluded from the fitted tile area.
Rendering Notes
- Highlighted copper uses the mask bucket when the source layer is top or bottom. The configured
minimum_routing_length_milsthreshold is applied to each connected routed-artwork component, so short segments remain highlighted when they are part of a longer connected route. Setconnected_highlight_filtertofalseto revert to per-primitive threshold checks and same-net pad/via selection without the physical-touch filter. - Selected pads and vias are highlighted only when the same net has highlighted routed artwork that physically touches them on that layer. This keeps via-only inner-layer pads from appearing as highlighted when no selected routing connects on that layer.
- Non-selected tracks, arcs, fills, and regions use topology/context coloring.
- Non-selected component pads are split into generated SMD and through-hole helper buckets, with colors mirrored into the native SMD/through-hole view settings. Free pads without component ownership are included in the same pad buckets.
- Non-selected via pads are cloned into a visible helper bucket.
- Through-hole pad and via drills are cloned into paste-colored geometry and a per-view overlay so drill openings stay visible above pad helper geometry. Non-plated pad holes use the JSON-configured
non_plated_holecolor. - Draftsman renders visible
ShowedLayersin reverse XML order. Generated views list drill overlays first, then pad/via helpers, then highlighted routes, with the visible source/context layer last so it renders underneath the helpers on internal-layer views. - IPC-4761 filled/capped vias render as copper without an open drill-hole overlay.
- Layer tiles are clustered in the remaining page area below the title/notes. Tile order starts with the top layer at the top of the cluster.
- Internal signal layers use visible helper/display layers where native top/bottom assembly-view buckets do not map cleanly.
This remains an experimental board-assembly-view hijack. The reusable logic in assembly_highlight.py is structured so future samples can swap in different geometry selection heuristics without rewriting the Draftsman page synthesis.
Source Code
from __future__ import annotations
import argparse
import json
import shutil
from pathlib import Path
from altium_monkey import AltiumDesign
from assembly_highlight import build_group_output, sample_relative
from autodoc_config import AutodocConfig
SAMPLE_DIR = Path(__file__).resolve().parent
EXAMPLES_DIR = SAMPLE_DIR.parent
CONFIG_DIR = SAMPLE_DIR / "configs"
OUTPUT_DIR = SAMPLE_DIR / "output"
OUTPUT_MANIFEST_FILENAME = "draftsman_netclass_autodoc_manifest.json"
DEFAULT_CONFIGS = (
CONFIG_DIR / "bunny_brain.json",
CONFIG_DIR / "rt_super_c1.json",
CONFIG_DIR / "loz_old_man.json",
)
def _reset_output_dir() -> None:
if OUTPUT_DIR.exists():
shutil.rmtree(OUTPUT_DIR)
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
def _process_config(config_path: Path) -> dict[str, object]:
config = AutodocConfig.from_json_file(config_path, examples_dir=EXAMPLES_DIR)
output_dir = OUTPUT_DIR / config.output_name
output_dir.mkdir(parents=True, exist_ok=True)
design = AltiumDesign.from_prjpcb(config.source_project)
pcbdoc = design.load_pcbdoc()
layers_ctx = pcbdoc.layers()
groups = [
build_group_output(
config=config,
group=group,
pcbdoc=pcbdoc,
stack=layers_ctx,
output_dir=output_dir,
)
for group in config.groups
]
manifest = {
"schema": config.schema,
"config": sample_relative(config_path, sample_dir=SAMPLE_DIR),
"project": sample_relative(config.source_project, sample_dir=EXAMPLES_DIR),
"pcbdoc": sample_relative(
Path(str(getattr(pcbdoc, "filepath", "") or "")),
sample_dir=EXAMPLES_DIR,
),
"output_dir": sample_relative(output_dir, sample_dir=SAMPLE_DIR),
"sheet_size": config.sheet_size.display_name,
"default_view_scale": config.view_scale,
"auto_fit_scale": config.auto_fit_scale,
"minimum_routing_length_mils": config.minimum_routing_length_mils,
"connected_highlight_filter": config.connected_highlight_filter,
"group_count": len(groups),
"groups": [
{
"id": group.group_id,
"title": group.title,
"output_stem": group.output_stem,
"draftsman_pcb_dwf": sample_relative(
group.draftsman_pcb_dwf,
sample_dir=SAMPLE_DIR,
),
"draftsman_cache_xml": sample_relative(
group.draftsman_cache_xml,
sample_dir=SAMPLE_DIR,
),
"effective_scale": group.effective_scale,
"minimum_routing_length_mils": group.minimum_routing_length_mils,
"connected_highlight_filter": group.connected_highlight_filter,
"layers": group.layers,
}
for group in groups
],
}
manifest_path = output_dir / OUTPUT_MANIFEST_FILENAME
manifest_path.write_text(
json.dumps(manifest, indent=2, ensure_ascii=False) + "\n",
encoding="utf-8",
)
return {
**manifest,
"manifest": sample_relative(manifest_path, sample_dir=SAMPLE_DIR),
}
def run(config_paths: tuple[Path, ...] = DEFAULT_CONFIGS) -> dict[str, object]:
_reset_output_dir()
project_manifests = [_process_config(path) for path in config_paths]
manifest = {
"schema": "altium-monkey.draftsman-netclass-autodoc.run.v1",
"output_dir": sample_relative(OUTPUT_DIR, sample_dir=SAMPLE_DIR),
"config_count": len(project_manifests),
"projects": project_manifests,
}
manifest_path = OUTPUT_DIR / OUTPUT_MANIFEST_FILENAME
manifest_path.write_text(
json.dumps(manifest, indent=2, ensure_ascii=False) + "\n",
encoding="utf-8",
)
return {
**manifest,
"manifest": sample_relative(manifest_path, sample_dir=SAMPLE_DIR),
}
def main(argv: list[str] | None = None) -> None:
parser = argparse.ArgumentParser(
description=(
"Generate grouped Draftsman board-assembly-view highlight pages "
"from JSON netclass/differential-pair config files."
)
)
parser.add_argument(
"--config",
type=Path,
action="append",
default=None,
help="JSON config to process. Can be provided more than once.",
)
args = parser.parse_args(argv)
manifest = run(config_paths=tuple(args.config or DEFAULT_CONFIGS))
print(f"Wrote output: {manifest['output_dir']}")
print(f"Processed configs: {manifest['config_count']}")
for project in manifest["projects"]:
print(f"Loaded project: {project['project']}")
print(f" Config: {project['config']}")
print(f" Groups: {project['group_count']}")
for group in project["groups"]:
layer_names = ", ".join(
str(layer["display_name"]) for layer in group["layers"]
)
print(
f" {group['title']}: {layer_names} "
f"(scale {group['effective_scale']:.3g})"
)
print(f" Wrote manifest: {project['manifest']}")
print(f"Wrote aggregate manifest: {manifest['manifest']}")
if __name__ == "__main__":
main()