Default create_schematic to A3 paper size with configurable parameter
Some checks are pending
CI / Security Scan (push) Waiting to run
CI / Build Package (push) Blocked by required conditions
CI / Lint and Format (push) Waiting to run
CI / Test Python 3.11 on macos-latest (push) Waiting to run
CI / Test Python 3.12 on macos-latest (push) Waiting to run
CI / Test Python 3.13 on macos-latest (push) Waiting to run
CI / Test Python 3.10 on ubuntu-latest (push) Waiting to run
CI / Test Python 3.11 on ubuntu-latest (push) Waiting to run
CI / Test Python 3.12 on ubuntu-latest (push) Waiting to run
CI / Test Python 3.13 on ubuntu-latest (push) Waiting to run

A4 is too small for real schematics. A3 matches US engineering
convention (close to ANSI B/Tabloid) and is KiCad's standard
template size. Batch JSON also supports paper_size field.
This commit is contained in:
Ryan Malloy 2026-03-09 00:45:27 -06:00
parent 458583ee08
commit 1297ca2ce1
2 changed files with 32 additions and 3 deletions

View File

@ -363,6 +363,14 @@ def _apply_batch_operations(
collisions_resolved = 0
wire_collisions_resolved = 0
# 0. Paper size (if specified in batch)
batch_paper = data.get("paper_size")
if batch_paper:
try:
sch.set_paper_size(batch_paper)
except Exception:
logger.warning("Could not set paper_size to '%s'", batch_paper)
# 1. Components (multi-unit supported natively by kicad-sch-api)
for comp in data.get("components", []):
ref = comp.get("reference")

View File

@ -104,8 +104,15 @@ def _expand(path: str) -> str:
# ---------------------------------------------------------------------------
_VALID_PAPER_SIZES = {"A4", "A3", "A2", "A1", "A0", "Letter", "Legal", "Tabloid"}
@mcp.tool()
def create_schematic(name: str, output_path: str) -> dict[str, Any]:
def create_schematic(
name: str,
output_path: str,
paper_size: str = "A3",
) -> dict[str, Any]:
"""Create a new, empty KiCad schematic file.
Generates a valid .kicad_sch file at the specified location that can be
@ -115,9 +122,12 @@ def create_schematic(name: str, output_path: str) -> dict[str, Any]:
name: Human-readable name for the schematic (e.g. "Power Supply").
output_path: Destination file path. Must end with .kicad_sch.
Parent directory will be created if it does not exist.
paper_size: Paper size for the schematic sheet. Default "A3".
Valid sizes: A4, A3, A2, A1, A0, Letter, Legal, Tabloid.
US schematics typically use A3 or Tabloid (ANSI B, 11x17").
Returns:
Dictionary with ``success``, ``path``, and ``engine`` keys.
Dictionary with ``success``, ``path``, ``paper_size``, and ``engine`` keys.
"""
err = _require_sch_api()
if err:
@ -131,19 +141,30 @@ def create_schematic(name: str, output_path: str) -> dict[str, Any]:
"error": f"output_path must end with .kicad_sch, got: {output_path}",
}
if paper_size not in _VALID_PAPER_SIZES:
return {
"success": False,
"error": (
f"Invalid paper_size '{paper_size}'. "
f"Valid sizes: {', '.join(sorted(_VALID_PAPER_SIZES))}"
),
}
try:
parent = os.path.dirname(output_path)
if parent:
os.makedirs(parent, exist_ok=True)
sch = _ksa_create(name)
sch.set_paper_size(paper_size)
sch.save(output_path)
logger.info("Created schematic '%s' at %s", name, output_path)
logger.info("Created schematic '%s' (%s) at %s", name, paper_size, output_path)
return {
"success": True,
"path": output_path,
"name": name,
"paper_size": paper_size,
"engine": _get_schematic_engine(),
}
except Exception as e: