# -*- coding: utf-8 -*- """批量放置元件:python .claude/place.py spec: [[designator, lcsc_uuid, x, y, rot], ...]""" import json, sys sys.path.insert(0, '.claude') from eda import run page, spec_file = sys.argv[1], sys.argv[2] spec = json.load(open(spec_file, encoding='utf-8')) 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] 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); await c.toAsync().setState_Designator(des).done(); out.push(des+' created'); } return {page:(await eda.dmt_Schematic.getCurrentSchematicPageInfo()).name, out}; """ % (page, json.dumps(spec)) r = run(js) print(json.dumps(r, ensure_ascii=False)[:3000])