← Commit history

Delete tools/silk_place.py

John Lauer ·9bc334a1db ·2d ago ·parent 1a6eb1c
1 file changed −52
tools/silk_place.pydeleted−52
@@ -1,52 +0,0 @@-#!/usr/bin/env python3-"""Place standalone silkscreen labels live through KiCad Bridge: for each label try candidate spots-(position, angle) at decreasing sizes, dry-run each against KiCad's own DRC, commit the first legal one.-Usage: silk_place.py <labels.json> <manifest-out.json>   (revision read/written in $REV_FILE)--labels.json: [{"id":..., "text":..., "layer":"F.SilkS"|"B.SilkS", "sizes":[0.8,0.6],-               "cands":[[x, y, angle], ...], "purpose":...}, ...]-"""-import json, os, subprocess, sys--BOARD = os.environ.get("BOARD", "C:/Users/john/Documents/buck-12v5v-molecule/kicad/buck-12v5v-molecule.kicad_pcb")-TARGET = os.environ.get("TARGET", "ConfRoomROG")-REV_FILE = os.environ["REV_FILE"]---def call(args):-    r = subprocess.run(["adom-bridge", "--target", TARGET, "kicad_silk_text_batch", json.dumps(args), "--ai-thread", "buck-repro"],-                       capture_output=True, text=True)-    d = json.loads(r.stdout); o = d.get("output", d)-    return json.loads(o) if isinstance(o, str) and o.startswith("{") else o---labels = json.load(open(sys.argv[1]))-manifest = []-rev = open(REV_FILE).read().strip()-for lab in labels:-    placed = None-    for size in lab.get("sizes", [0.8]):-        for x, y, ang in lab["cands"]:-            item = {"text": lab["text"], "layer": lab["layer"], "x": x, "y": y, "width": size, "height": size,-                    "stroke": round(max(0.1, size * 0.15), 3)}-            if ang:-                item["angle"] = ang-            base = {"filePath": BOARD, "expectedRevision": rev, "create": [item], "reason": f"silkscreen: {lab['id']}"}-            dry = call(dict(base, dryRun=True))-            if not dry.get("success"):-                if dry.get("errorCode") not in ("drc_rejected",):-                    print(f"  {lab['id']}: {dry.get('errorCode')} {str(dry.get('error'))[:120]}")-                    if dry.get("errorCode") in ("stale_board",):-                        sys.exit(1)-                continue-            live = call(base)-            if not live.get("success"):-                print(f"  {lab['id']}: commit failed {live.get('errorCode')} {live.get('error')}"); continue-            rev = live.get("revision", rev); open(REV_FILE, "w").write(rev)-            placed = dict(item, id=lab["id"], purpose=lab.get("purpose", ""))-            break-        if placed:-            break-    manifest.append(placed or {"id": lab["id"], "text": lab["text"], "layer": lab["layer"], "unresolved": True, "purpose": lab.get("purpose", "")})-    print(("ok " if placed else "UNRESOLVED ") + f"{lab['id']}: {lab['text']} {lab['layer']}" + (f" at ({placed['x']},{placed['y']}) {placed['width']} mm" if placed else ""))-json.dump(manifest, open(sys.argv[2], "w"), indent=1)