# -*- coding: utf-8 -*- u"""把**下板 PCB1** 当前的全部铜/元件状态落成一个 JSON(可回滚的安全网)。 2026-09-07 从 pcb2_snapshot.py 改 PCB uuid 得到,其余一模一样。 /c/Python314/python .claude/_pcb1_snapshot.py # 路径相对 .claude/ 抓:元件 (位号,x,y,rot,layer)、导线、过孔、铺铜(含多边形)、自由焊盘、layer 11 多段线、填充。 单位 mil(EasyEDA 原生),不换算。 """ import io, json, os, sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) from eda import run PCB = '7e9415a16a909c51' JS = u""" await eda.dmt_EditorControl.openDocument('%s'); await new Promise(r=>setTimeout(r,1500)); const out = {comps:[], lines:[], vias:[], pours:[], fills:[], pads:[], polys:[], arcs:[]}; for (const c of await eda.pcb_PrimitiveComponent.getAll()) out.comps.push([c.getState_Designator(), c.getState_X(), c.getState_Y(), c.getState_Rotation(), c.getState_Layer()]); for (const l of await eda.pcb_PrimitiveLine.getAll()) out.lines.push([l.layer, l.startX, l.startY, l.endX, l.endY, l.lineWidth, l.net]); for (const a of await eda.pcb_PrimitiveArc.getAll()) out.arcs.push([a.layer, a.net, JSON.stringify(a).slice(0, 400)]); for (const v of await eda.pcb_PrimitiveVia.getAll()) out.vias.push([v.x, v.y, v.holeDiameter, v.diameter, v.net]); for (const p of await eda.pcb_PrimitivePour.getAll()) { let poly = null; try { poly = p.complexPolygon; } catch(e) {} out.pours.push({layer: p.layer, net: p.net, name: p.pourName, prio: p.pourPriority, fill: p.pourFillMethod, poly: poly ? JSON.parse(JSON.stringify(poly)) : null}); } for (const f of await eda.pcb_PrimitiveFill.getAll()) out.fills.push({layer: f.layer, net: f.net, raw: JSON.parse(JSON.stringify(f)).complexPolygon || null}); for (const p of await eda.pcb_PrimitivePad.getAll()) { const pid = p.getState_PrimitiveId(); out.pads.push([pid, p.getState_PadNumber(), p.getState_Layer(), p.getState_X(), p.getState_Y(), p.getState_Net()]); } for (const p of await eda.pcb_PrimitivePolyline.getAll()) out.polys.push({layer: p.layer, raw: JSON.parse(JSON.stringify(p))}); return out; """ % PCB if __name__ == '__main__': r = run(JS, timeout=300) if not r.get('success'): print(json.dumps(r, ensure_ascii=False)[:800]); sys.exit(1) res = r['result'] out = os.path.join(HERE, sys.argv[1] if len(sys.argv) > 1 else '_pcb2_snap.json') io.open(out, 'w', encoding='utf-8').write(json.dumps(res)) print(u'元件 %d / 导线 %d / 弧 %d / 过孔 %d / 铺铜 %d / 填充 %d / 焊盘 %d / 多段线 %d -> %s' % ( len(res['comps']), len(res['lines']), len(res['arcs']), len(res['vias']), len(res['pours']), len(res['fills']), len(res['pads']), len(res['polys']), out))