# -*- coding: utf-8 -*- """放置 P4 元件(支持 mirror),并回读引脚。用法: python .claude/place4.py """ import json, sys, os HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) from eda import run from p4_pos import SPEC page = sys.argv[1] js = """ await eda.dmt_EditorControl.openDocument('%s'); const LIB='0819f05c4eef4c71ace90d822a990e87'; const spec=%s; const have={}; for (const c of await eda.sch_PrimitiveComponent.getAll()) if (c.getState_ComponentType()==='part') have[c.getState_Designator()]=c; const out=[]; for (const [des,uuid,x,y,rot,mir] of spec){ if (have[des]) { await have[des].toAsync().setState_X(x).setState_Y(y).setState_Rotation(rot).done(); out.push(des+' moved'); continue; } const c = await eda.sch_PrimitiveComponent.create({libraryUuid:LIB,uuid}, x, y, undefined, rot, mir); await c.toAsync().setState_Designator(des).done(); out.push(des+' created'); } return {page:(await eda.dmt_Schematic.getCurrentSchematicPageInfo()).name, n:out.length, out:out.slice(0,6)}; """ % (page, json.dumps(SPEC)) print(json.dumps(run(js, timeout=300), ensure_ascii=False)[:2000])