main
John Lauer Preserve board29, component assets and scaffold-fit correction candidate with reviewed footage c54169e
"""Run on the native desktop KiCad Python; preserve the routed board and rules."""
import pcbnew as k,json,shutil,subprocess,sys
from pathlib import Path
p=Path(__file__).parent
results=[]
for width in [1.5,2.0]:
 name='power-width-'+str(width).replace('.','p')
 b=k.LoadBoard(str(p/'source.kicad_pcb'));changed=[]
 for t in b.GetTracks():
  if isinstance(t,k.PCB_VIA):continue
  if t.GetNetname() in ['DUT_POS','DUT_FUSED','LOAD_POS','SHUNT_P'] and abs(k.ToMM(t.GetWidth())-1.2)<1e-6:
   changed.append({'uuid':str(t.m_Uuid.AsString()),'net':t.GetNetname(),'oldWidthMm':1.2,'newWidthMm':width});t.SetWidth(k.FromMM(width))
 for ext in ['kicad_dru','kicad_pro']:
  if (p/('source.'+ext)).exists():shutil.copy2(p/('source.'+ext),p/(name+'.'+ext))
 k.ZONE_FILLER(b).Fill(b.Zones());k.SaveBoard(str(p/(name+'.kicad_pcb')),b)
 proc=subprocess.run([str(Path(sys.executable).parent/'kicad-cli.exe'),'pcb','drc','--format','json','-o',str(p/(name+'-drc.json')),str(p/(name+'.kicad_pcb'))],capture_output=True,text=True)
 if not (p/(name+'-drc.json')).exists():raise RuntimeError(proc.stderr)
 d=json.loads((p/(name+'-drc.json')).read_text());results.append({'name':name,'changed':changed,'errors':sum(x.get('severity')=='error' for x in d.get('violations',[])),'warnings':sum(x.get('severity')=='warning' for x in d.get('violations',[])),'unconnected':len(d.get('unconnected_items',[]))})
(p/'width-review.json').write_text(json.dumps(results,indent=2));print(json.dumps([{k:v for k,v in x.items() if k!='changed'} for x in results]))