On This Page (5)
Examples Showcase / pcbdoc_vgroove_panel
Author a 1x4 HydroScope V-groove (V-score) panel
Build a 0-gap 1x4 HydroScope Mainboard V-groove panel with top and bottom breakaway rails, full-width V-score lines, copper-free NPTH corner tooling holes, IPC-7351 circular fiducials, panel PnP, and top/bottom SVGs.
Output Previews
Build a 1x4 V-groove (V-score) manufacturing panel of the rectangular HydroScope Mainboard (TZ-SB-0001-PCB-[A] (HydroScope Mainboard).PcbDoc) using AltiumPcbDoc.add_embedded_board_array(...) with 0 mil board-to-board spacing, top and bottom breakaway rails, full-width V-score lines, copper-free NPTH tooling holes, IPC-7351 circular global fiducials, and panel-level Pick-and-Place / SVG outputs through Fab.
What It Shows
- Placing a rectangular board (
4500 x 970 mil) in a 0-gap 1x4 array viaadd_embedded_board_array(...)so V-score blades cut straight across the panel width - Separating mechanical panel layers:
MECHANICAL1(gold in SVG): outer panel outline and individual board edgesMECHANICAL2(pink/magenta in SVG): 5 full-width horizontal and 2 full-height vertical V-score lines withV-SCOREcallouts separating the four breakaway rails and adjacent boards
- Adding copper-free NPTH corner tooling holes (125 mil / 3.175 mm) and 3 asymmetric IPC-7351 circular global fiducials (1.0 mm copper disk, 2.0 mm solder mask opening, paste suppressed) on both top and bottom rails
- Querying
FabViewstep-repeat and flattened geometry and writing top/bottom panel SVGs plus Pick-and-Place CSV
See also pcbdoc_embedded_board_panel for a tab-routed panel with NPTH mouse bites on all 4 sides of every board.
Run
From the repository root:
uv run python examples\pcbdoc_vgroove_panel\pcbdoc_vgroove_panel.pyOutput
The script writes:
examples/pcbdoc_vgroove_panel/output/hydroscope_vgroove_panel_1x4.PcbDoc
examples/pcbdoc_vgroove_panel/output/vgroove_1x4_top.svg
examples/pcbdoc_vgroove_panel/output/vgroove_1x4_bottom.svg
examples/pcbdoc_vgroove_panel/output/vgroove_pnp.csv
examples/pcbdoc_vgroove_panel/output/vgroove_manifest.jsonSource Code
from __future__ import annotations
import json
import shutil
from pathlib import Path
from altium_monkey import (
AltiumBoardOutline,
AltiumPcbDoc,
BoardOutlineVertex,
PadShape,
PcbLayer,
)
from altium_monkey.altium_pcb_embedded_board import (
PcbEmbeddedBoardOriginMode,
interpret_embedded_boards,
)
from altium_monkey.altium_pcb_mask_expansion import PcbMaskExpansionMode
SAMPLE_DIR = Path(__file__).resolve().parent
EXAMPLES_DIR = SAMPLE_DIR.parent
CHILD_PCBDOC = (
EXAMPLES_DIR
/ "assets"
/ "projects"
/ "hydroscope"
/ "TZ-SB-0001-PCB-[A] (HydroScope Mainboard).PcbDoc"
)
CHILD_REL_FROM_OUTPUT = (
"../../assets/projects/hydroscope/TZ-SB-0001-PCB-[A] (HydroScope Mainboard).PcbDoc"
)
OUTPUT_DIR = SAMPLE_DIR / "output"
PANEL_PATH = OUTPUT_DIR / "hydroscope_vgroove_panel_1x4.PcbDoc"
TOP_SVG_PATH = OUTPUT_DIR / "vgroove_1x4_top.svg"
BOTTOM_SVG_PATH = OUTPUT_DIR / "vgroove_1x4_bottom.svg"
PNP_CSV_PATH = OUTPUT_DIR / "vgroove_pnp.csv"
MANIFEST_PATH = OUTPUT_DIR / "vgroove_manifest.json"
# HydroScope Mainboard is a 4500 x 970 mil (114.30 x 24.64 mm) rectangle.
# V-scored boards abut with 0 mil spacing along the horizontal score lines,
# with breakaway rails on all four sides separated by full-span horizontal and
# vertical V-score lines.
BOARD_WIDTH_MILS = 4500.0
BOARD_HEIGHT_MILS = 970.0
ROWS = 4
COLUMNS = 1
RAIL_X_MILS = 350.0 # ~8.89 mm left/right breakaway rails
RAIL_Y_MILS = 350.0 # ~8.89 mm top/bottom breakaway rails
PANEL_WIDTH_MILS = 2.0 * RAIL_X_MILS + BOARD_WIDTH_MILS
PANEL_HEIGHT_MILS = 2.0 * RAIL_Y_MILS + ROWS * BOARD_HEIGHT_MILS
# IPC-7351 / SMEMA global panel fiducial: 1.0 mm copper disk, 2.0 mm mask opening.
FIDUCIAL_CU_DIA_MILS = 39.37
FIDUCIAL_MASK_EXP_MILS = 19.685
def _sample_relative(path: Path) -> str:
return path.relative_to(SAMPLE_DIR).as_posix()
def _examples_relative(path: Path) -> str:
return path.relative_to(EXAMPLES_DIR).as_posix()
def _rect_outline(width_mils: float, height_mils: float) -> AltiumBoardOutline:
return AltiumBoardOutline(
vertices=[
BoardOutlineVertex.line(0.0, 0.0),
BoardOutlineVertex.line(width_mils, 0.0),
BoardOutlineVertex.line(width_mils, height_mils),
BoardOutlineVertex.line(0.0, height_mils),
]
)
def _draw_rect_tracks(
panel: AltiumPcbDoc,
x0: float,
y0: float,
x1: float,
y1: float,
*,
width_mils: float,
layer: PcbLayer,
) -> None:
corners = [(x0, y0), (x1, y0), (x1, y1), (x0, y1)]
for idx in range(4):
panel.add_track(
corners[idx],
corners[(idx + 1) % 4],
width_mils=width_mils,
layer=layer,
)
def _add_npth_hole(
panel: AltiumPcbDoc,
*,
designator: str,
position_mils: tuple[float, float],
hole_size_mils: float,
) -> None:
"""Add a copper-free non-plated through hole."""
panel.add_pad(
designator=designator,
position_mils=position_mils,
width_mils=0.0,
height_mils=0.0,
hole_size_mils=hole_size_mils,
plated=False,
shape=PadShape.CIRCLE,
layer=PcbLayer.MULTI_LAYER,
solder_mask_expansion_mode=PcbMaskExpansionMode.MANUAL,
solder_mask_expansion_mils=0.0,
)
def _add_ipc_fiducial(
panel: AltiumPcbDoc,
*,
designator: str,
position_mils: tuple[float, float],
) -> None:
"""Add an IPC-7351 circular global fiducial on both TOP and BOTTOM rails."""
for layer in (PcbLayer.TOP, PcbLayer.BOTTOM):
panel.add_pad(
designator=designator,
position_mils=position_mils,
width_mils=FIDUCIAL_CU_DIA_MILS,
height_mils=FIDUCIAL_CU_DIA_MILS,
hole_size_mils=0.0,
shape=PadShape.CIRCLE,
layer=layer,
solder_mask_expansion_mode=PcbMaskExpansionMode.MANUAL,
solder_mask_expansion_mils=FIDUCIAL_MASK_EXP_MILS,
paste_mask_expansion_mode=PcbMaskExpansionMode.MANUAL,
paste_mask_expansion_mils=-FIDUCIAL_MASK_EXP_MILS,
)
def build_vgroove_panel_example(output_dir: Path = OUTPUT_DIR) -> dict[str, object]:
if output_dir.exists():
shutil.rmtree(output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
panel_path = output_dir / "hydroscope_vgroove_panel_1x4.PcbDoc"
top_svg_path = output_dir / "vgroove_1x4_top.svg"
bottom_svg_path = output_dir / "vgroove_1x4_bottom.svg"
pnp_csv_path = output_dir / "vgroove_pnp.csv"
manifest_path = output_dir / "vgroove_manifest.json"
loaded_child = AltiumPcbDoc.from_file(CHILD_PCBDOC)
panel = AltiumPcbDoc()
panel.set_board_outline(_rect_outline(PANEL_WIDTH_MILS, PANEL_HEIGHT_MILS))
panel.set_origin_to_outline_lower_left()
# 1. Place a 1x4 embedded board array with 0 mil vertical gap for V-scoring.
panel.add_embedded_board_array(
loaded_child,
document_path=CHILD_REL_FROM_OUTPUT,
position_mils=(RAIL_X_MILS, RAIL_Y_MILS),
rows=ROWS,
columns=COLUMNS,
row_pitch_mils=BOARD_HEIGHT_MILS,
column_pitch_mils=BOARD_WIDTH_MILS,
origin_mode=PcbEmbeddedBoardOriginMode.BOTTOM_LEFT,
layer=PcbLayer.TOP,
)
# 2. Add 4 copper-free NPTH corner tooling holes (3.175 mm / 125 mil) on rails.
tooling_coords = (
(175.0, 175.0),
(PANEL_WIDTH_MILS - 175.0, 175.0),
(175.0, PANEL_HEIGHT_MILS - 175.0),
(PANEL_WIDTH_MILS - 175.0, PANEL_HEIGHT_MILS - 175.0),
)
for idx, pos in enumerate(tooling_coords, start=1):
_add_npth_hole(
panel,
designator=f"TH{idx}",
position_mils=pos,
hole_size_mils=125.0,
)
# 3. Add 3 asymmetric IPC-7351 circular global fiducials on top/bottom rails.
fiducial_coords = (
(RAIL_X_MILS + 250.0, RAIL_Y_MILS / 2.0),
(PANEL_WIDTH_MILS - RAIL_X_MILS - 250.0, RAIL_Y_MILS / 2.0),
(RAIL_X_MILS + 250.0, PANEL_HEIGHT_MILS - RAIL_Y_MILS / 2.0),
)
for idx, (fx, fy) in enumerate(fiducial_coords, start=1):
_add_ipc_fiducial(panel, designator=f"FID{idx}", position_mils=(fx, fy))
panel.add_text(
text=f"FID{idx}",
position_mils=(fx + 95.0, fy - 22.0),
height_mils=45.0,
stroke_width_mils=8.0,
layer=PcbLayer.TOP_OVERLAY,
)
# 4. Draw outer panel border and board outlines on MECHANICAL1, and
# continuous full-span horizontal and vertical V-score lines on MECHANICAL2.
_draw_rect_tracks(
panel,
0.0,
0.0,
PANEL_WIDTH_MILS,
PANEL_HEIGHT_MILS,
width_mils=12.0,
layer=PcbLayer.MECHANICAL_1,
)
for row in range(ROWS):
by0 = RAIL_Y_MILS + row * BOARD_HEIGHT_MILS
_draw_rect_tracks(
panel,
RAIL_X_MILS,
by0,
RAIL_X_MILS + BOARD_WIDTH_MILS,
by0 + BOARD_HEIGHT_MILS,
width_mils=8.0,
layer=PcbLayer.MECHANICAL_1,
)
vscore_ys = [RAIL_Y_MILS + idx * BOARD_HEIGHT_MILS for idx in range(ROWS + 1)]
for score_y in vscore_ys:
panel.add_track(
(0.0, score_y),
(PANEL_WIDTH_MILS, score_y),
width_mils=18.0,
layer=PcbLayer.MECHANICAL_2,
)
# Top-side V-SCORE callout (readable on top view)
panel.add_text(
text="V-SCORE",
position_mils=(35.0, score_y + 24.0),
height_mils=36.0,
stroke_width_mils=6.0,
layer=PcbLayer.MECHANICAL_3,
)
# Bottom-side mirrored V-SCORE callout (readable forward when mirrored in bottom view)
panel.add_text(
text="V-SCORE",
position_mils=(PANEL_WIDTH_MILS - 35.0, score_y + 24.0),
height_mils=36.0,
stroke_width_mils=6.0,
is_mirrored=True,
layer=PcbLayer.MECHANICAL_4,
)
vscore_xs = [RAIL_X_MILS, RAIL_X_MILS + BOARD_WIDTH_MILS]
for score_x in vscore_xs:
panel.add_track(
(score_x, 0.0),
(score_x, PANEL_HEIGHT_MILS),
width_mils=18.0,
layer=PcbLayer.MECHANICAL_2,
)
panel.add_text(
text="V-SCORE",
position_mils=(score_x - 24.0, RAIL_Y_MILS + 320.0),
height_mils=36.0,
stroke_width_mils=6.0,
rotation_degrees=90.0,
layer=PcbLayer.MECHANICAL_3,
)
panel.add_text(
text="V-SCORE",
position_mils=(score_x + 24.0, RAIL_Y_MILS + 320.0),
height_mils=36.0,
stroke_width_mils=6.0,
rotation_degrees=270.0,
is_mirrored=True,
layer=PcbLayer.MECHANICAL_4,
)
# 5. Add silkscreen panel notes on top and bottom breakaway rails.
panel.add_text(
text=(
f"HYDROSCOPE 1x4 V-GROOVE PANEL "
f"({PANEL_WIDTH_MILS / 1000.0:.2f} x {PANEL_HEIGHT_MILS / 1000.0:.2f} IN)"
),
position_mils=(RAIL_X_MILS + 680.0, PANEL_HEIGHT_MILS - 210.0),
height_mils=64.0,
stroke_width_mils=10.0,
layer=PcbLayer.TOP_OVERLAY,
)
panel.add_text(
text="M2: X/Y V-SCORE (0MM GAP, 1/3 WEB) | NPTH TOOLING: 3.18MM | FID: 1MM CU / 2MM MASK",
position_mils=(RAIL_X_MILS + 650.0, 145.0),
height_mils=42.0,
stroke_width_mils=7.0,
layer=PcbLayer.TOP_OVERLAY,
)
panel.save(panel_path)
# 6. Reload and emit Fab outputs.
reloaded = AltiumPcbDoc.from_file(panel_path)
arrays = interpret_embedded_boards(reloaded.embedded_boards)
fab = reloaded.fab()
top_svg = fab.to_svg(
scale=3.0,
layers=(
"PROFILE",
"TOP",
"TOPSOLDER",
"TOPOVERLAY",
"MECHANICAL1",
"MECHANICAL2",
"MECHANICAL3",
"DRILLS",
),
layer_colours={
"PROFILE": "#14171C",
"TOP": "#2C333D",
"TOPSOLDER": "rgba(235, 193, 74, 0.90)",
"TOPOVERLAY": "#F5F7FA",
"MECHANICAL1": "#F5C542",
"MECHANICAL2": "#FF5E7E",
"MECHANICAL3": "#FF5E7E",
"DRILLS": "#FFFFFF",
},
clip_to_outline=True,
metadata=True,
)
top_svg_path.write_bytes(top_svg["board.svg"].data)
bottom_svg = fab.to_svg(
scale=3.0,
layers=(
"PROFILE",
"BOTTOM",
"BOTTOMSOLDER",
"BOTTOMOVERLAY",
"MECHANICAL1",
"MECHANICAL2",
"MECHANICAL4",
"DRILLS",
),
layer_colours={
"PROFILE": "#14171C",
"BOTTOM": "#2C333D",
"BOTTOMSOLDER": "rgba(235, 193, 74, 0.90)",
"BOTTOMOVERLAY": "#F5F7FA",
"MECHANICAL1": "#F5C542",
"MECHANICAL2": "#FF5E7E",
"MECHANICAL4": "#FF5E7E",
"DRILLS": "#FFFFFF",
},
mirror=True,
clip_to_outline=True,
metadata=True,
)
bottom_svg_path.write_bytes(bottom_svg["board.svg"].data)
pnp_out = fab.to_pnp(panel={"copy_designators": "$Component_$CopyIndex"})
pnp_file = next(iter(pnp_out.values()))
pnp_csv_path.write_bytes(pnp_file.data)
pnp_rows = [line for line in pnp_file.text.splitlines() if line.strip()]
step_view = fab.view(copies="steps")
repeats = step_view.repeats()
flat_view = fab.view(copies="flatten")
manifest: dict[str, object] = {
"child_board": _examples_relative(CHILD_PCBDOC),
"panel_file": _sample_relative(panel_path),
"panel_size_mils": [PANEL_WIDTH_MILS, PANEL_HEIGHT_MILS],
"embedded_board_count": len(arrays),
"vscore_lines_y_mils": vscore_ys,
"vscore_lines_x_mils": vscore_xs,
"panel_features": {
"tooling_holes_npth": len(tooling_coords),
"fiducials_ipc7351_circular": len(fiducial_coords),
"vscore_lines_horizontal": len(vscore_ys),
"vscore_lines_vertical": len(vscore_xs),
"board_gap_mils": 0.0,
},
"fab_step_repeats": len(repeats),
"flattened_hole_count": len(flat_view.holes()),
"panel_pnp_rows": max(0, len(pnp_rows) - 1),
"outputs": {
"top_svg": _sample_relative(top_svg_path),
"bottom_svg": _sample_relative(bottom_svg_path),
"pnp_csv": _sample_relative(pnp_csv_path),
},
}
manifest_path.write_text(
json.dumps(manifest, indent=2) + "\n", encoding="utf-8", newline="\n"
)
return manifest
def main() -> None:
manifest = build_vgroove_panel_example()
print(json.dumps(manifest, indent=2))
if __name__ == "__main__":
main()