# -*- coding: utf-8 -*- u"""下板 PCB1:拆掉全部铜(导线 / 过孔 / 铺铜边框),只留板框、定位孔与元件。 2026-09-06 两板拆分之后,板上那 5813 条线 / 1208 个孔全是**单板时代**自动布线的结果, 网络表已经换过(删 70 件 / 加 17 件),布局也整块重排 —— 一条都留不得。 ⚠️ 保留:layer 11 板框、layer 12 的 M3 焊盘、丝印。 用法: /c/Python314/python .claude/pcb1_clear.py [--push] """ import json, os, sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) from eda import run PCB = '7e9415a16a909c51' COPPER = (1, 2, 15, 16) def call(body, timeout=600): r = run("await eda.dmt_EditorControl.openDocument('%s');" "await new Promise(r=>setTimeout(r,1500));" % PCB + body, timeout=timeout) if not r.get('success'): sys.exit(json.dumps(r, ensure_ascii=False)[:600]) return r['result'] COUNT = """ const L = {}, out = {vias: 0, pours: 0, polylines: {}}; for (const l of await eda.pcb_PrimitiveLine.getAll()) L[l.layer] = (L[l.layer] || 0) + 1; out.lines = L; out.vias = (await eda.pcb_PrimitiveVia.getAll()).length; out.pours = (await eda.pcb_PrimitivePour.getAll()).length; for (const p of await eda.pcb_PrimitivePolyline.getAll()) out.polylines[p.layer] = (out.polylines[p.layer] || 0) + 1; out.fills = (await eda.pcb_PrimitiveFill.getAll()).length; return out; """ def show(tag): r = call(COUNT) print(u'%s 导线 %s / 过孔 %d / 铺铜边框 %d / 多段线 %s / 填充 %d' % (tag, r['lines'], r['vias'], r['pours'], r['polylines'], r['fills'])) return r def wipe(): total = {'lines': 0, 'vias': 0, 'pours': 0} for _ in range(30): # 一次删太多会超时,分批删到删不动为止 r = call(""" const COPPER = %s; let nl = 0, nv = 0, np = 0; for (const l of await eda.pcb_PrimitiveLine.getAll()) { if (COPPER.includes(l.layer) && nl < 1500) { await eda.pcb_PrimitiveLine.delete(l.primitiveId); nl++; } } for (const v of await eda.pcb_PrimitiveVia.getAll()) { if (nv < 800) { await eda.pcb_PrimitiveVia.delete(v.primitiveId); nv++; } } for (const p of await eda.pcb_PrimitivePour.getAll()) { await eda.pcb_PrimitivePour.delete(p.primitiveId); np++; } return {nl, nv, np}; """ % json.dumps(list(COPPER))) for k, v in (('lines', r['nl']), ('vias', r['nv']), ('pours', r['np'])): total[k] += v print(u' 删 导线 %d / 过孔 %d / 铺铜 %d' % (r['nl'], r['nv'], r['np'])) if r['nl'] == 0 and r['nv'] == 0 and r['np'] == 0: break call("await eda.pcb_Document.save(); return 1;") print(u'共删 导线 %(lines)d / 过孔 %(vias)d / 铺铜边框 %(pours)d' % total) if __name__ == '__main__': show(u'拆之前:') if '--push' in sys.argv: wipe() show(u'拆之后:') else: print(u'(只统计。要真的拆加 --push)')