diff --git a/src/mckicad/tools/batch.py b/src/mckicad/tools/batch.py index 2f586af..80b446b 100644 --- a/src/mckicad/tools/batch.py +++ b/src/mckicad/tools/batch.py @@ -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") diff --git a/src/mckicad/tools/schematic.py b/src/mckicad/tools/schematic.py index cc6e2a1..898d601 100644 --- a/src/mckicad/tools/schematic.py +++ b/src/mckicad/tools/schematic.py @@ -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: