Home > PCB_PrimitiveComponent > modify
PCB_PrimitiveComponent.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改器件
签名
function modify(
primitiveId: string | IPCB_PrimitiveComponent,
property: {
layer?: undefined | EPCB_LayerId.TOP | EPCB_LayerId.BOTTOM;
x?: undefined | number;
y?: undefined | number;
rotation?: undefined | number;
primitiveLock?: undefined | false | true;
addIntoBom?: undefined | false | true;
designator?: undefined | null | string;
name?: undefined | null | string;
uniqueId?: undefined | null | string;
manufacturer?: undefined | null | string;
manufacturerId?: undefined | null | string;
supplier?: undefined | null | string;
supplierId?: undefined | null | string;
otherProperty?: undefined | Record<string, any>;
},
): Promise<IPCB_PrimitiveComponent | undefined>;2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveId | string | IPCB_PrimitiveComponent | 图元 ID |
property | { layer?: undefined | EPCB_LayerId.TOP | EPCB_LayerId.BOTTOM; x?: undefined | number; y?: undefined | number; rotation?: undefined | number; primitiveLock?: undefined | false | true; addIntoBom?: undefined | false | true; designator?: undefined | null | string; name?: undefined | null | string; uniqueId?: undefined | null | string; manufacturer?: undefined | null | string; manufacturerId?: undefined | null | string; supplier?: undefined | null | string; supplierId?: undefined | null | string; otherProperty?: undefined | Record<string, any> } |
返回值
Promise<IPCB_PrimitiveComponent | undefined>
器件图元对象
示例
// 1. 放置待修改的测试器件(随机坐标避免与画布已有器件重合):
// 按立创编号从系统库精确反查器件,返回项不含 libraryUuid,需补上才能用于 create
const x = 20000 + Math.floor(Math.random() * 80000);
const y = 20000 + Math.floor(Math.random() * 80000);
const devices = await eda.lib_Device.searchByProperties({ supplierId: 'C1523' }, undefined, undefined, undefined, 5, 1);
const sysLibUuid = await eda.lib_LibrariesList.getSystemLibraryUuid();
const comp = await eda.pcb_PrimitiveComponent.create({ libraryUuid: sysLibUuid, uuid: devices[0].uuid }, 1, x, y);
const compId = comp.getState_PrimitiveId();
// 2. 读取修改前的位置与旋转角度
const beforeX = comp.getState_X();
const beforeY = comp.getState_Y();
const beforeRotation = comp.getState_Rotation();
// 3. 批量修改:平移 500mil,旋转 0° → 90°
await eda.pcb_PrimitiveComponent.modify(compId, { x: beforeX + 500, y: beforeY + 500, rotation: 90 });
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.pcb_PrimitiveComponent.get(compId);
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', compId);
console.log('x:', beforeX, '→', refreshed.getState_X());
console.log('y:', beforeY, '→', refreshed.getState_Y());
console.log('rotation:', beforeRotation, '→', refreshed.getState_Rotation());2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25