On This Page (5)
Examples Showcase / fab_micro_step_3d
Pure-Python ISO 10303-21 AP242 Micro-STEP 3D CAD Export
Export top and bottom AP242 Micro-STEP 3D CAD assemblies from KiCadFabView with board outline, interior cutout, copper pads/tracks/vias, drill rings, and highlighted test points — zero OCCT or KiCad runtime required.
Export self-contained ISO 10303-21 AP242 Micro-STEP 3D CAD models directly from KiCadFabView with zero OpenCASCADE, FreeCAD, or KiCad CLI runtime. The script generates top and bottom copper alignment assemblies for impedance_4layer.kicad_pcb with highlighted test points and drill rings.
What It Shows
- Opening
KiCadPcb.fab()on a 4-layer board with an interior cutout and test points - Configuring
FabMicroStepOptionsfor AP242 STEP output, drill overlays, and test-point highlighting - Writing pure-Python
.stepfiles withFab.to_micro_step()and reportingMicroStepStats
Input
examples/assets/projects/impedance_4layer/impedance_4layer.kicad_pcbRun
From the repository root:
uv run python examples/fab_micro_step_3d/fab_micro_step_3d.pyOutput
examples/fab_micro_step_3d/output/impedance_4layer_top.step
examples/fab_micro_step_3d/output/impedance_4layer_bottom.step
examples/fab_micro_step_3d/output/micro_step_stats.jsonSource Code
"""Generate pure-Python ISO 10303-21 AP242 Micro-STEP 3D CAD files from KiCadFabView."""
from __future__ import annotations
import json
from dataclasses import asdict
from pathlib import Path
from kicad_monkey import KiCadPcb
from kicad_monkey.fab import FabMicroStepOptions
HERE = Path(__file__).resolve().parent
INPUT_PCB = HERE.parent / "assets" / "projects" / "impedance_4layer" / "impedance_4layer.kicad_pcb"
OUT_DIR = HERE / "output"
def main() -> None:
OUT_DIR.mkdir(parents=True, exist_ok=True)
pcb = KiCadPcb.from_file(INPUT_PCB)
fab = pcb.fab(stem="impedance_4layer")
# 1. Top-side AP242 Micro-STEP with board outline, interior cutout, copper, drill rings, and highlighted test points
top_step_path = OUT_DIR / "impedance_4layer_top.step"
top_stats = fab.to_micro_step(
top_step_path,
options=FabMicroStepOptions(
layer_key="TOP",
schema="ap242",
include_cutouts=True,
include_lands=True,
include_strokes=True,
include_vias=True,
drill_mode="overlay",
highlight_test_points=True,
highlight_color=(0.95, 0.15, 0.15),
),
)
# 2. Bottom-side AP242 Micro-STEP showing B.Cu differential routing and via drill rings
bot_step_path = OUT_DIR / "impedance_4layer_bottom.step"
bot_stats = fab.to_micro_step(
bot_step_path,
options=FabMicroStepOptions(
layer_key="BOTTOM",
schema="ap242",
include_cutouts=True,
include_lands=True,
include_strokes=True,
include_vias=True,
drill_mode="overlay",
),
)
summary = {
"input_board": INPUT_PCB.name,
"top_step": {"file": top_step_path.name, **asdict(top_stats)},
"bottom_step": {"file": bot_step_path.name, **asdict(bot_stats)},
}
(OUT_DIR / "micro_step_stats.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
print(
f"Top Micro-STEP ({top_step_path.name}): {top_stats.solid_count} solids, "
f"{top_stats.entity_count} ISO-10303-21 entities ({top_stats.byte_length:,} bytes)"
)
print(
f"Bottom Micro-STEP ({bot_step_path.name}): {bot_stats.solid_count} solids, "
f"{bot_stats.entity_count} ISO-10303-21 entities ({bot_stats.byte_length:,} bytes)"
)
if __name__ == "__main__":
main()