Home > PCB_PrimitiveComponent > modify
PCB_PrimitiveComponent.modify() method
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Modify Device
Signature
typescript
function modify(
primitiveId: string | IPCB_PrimitiveComponent,
property: {
layer?: TPCB_LayersOfComponent;
x?: number;
y?: number;
rotation?: number;
primitiveLock?: boolean;
addIntoBom?: boolean;
designator?: string | null;
name?: string | null;
uniqueId?: string | null;
manufacturer?: string | null;
manufacturerId?: string | null;
supplier?: string | null;
supplierId?: string | null;
otherProperty?: Record<string, any>;
},
): Promise<IPCB_PrimitiveComponent | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | IPCB_PrimitiveComponent | Primitive ID |
property | { layer?: TPCB_LayersOfComponent; x?: number; y?: number; rotation?: number; primitiveLock?: boolean; addIntoBom?: boolean; designator?: string | null; name?: string | null; uniqueId?: string | null; manufacturer?: string | null; manufacturerId?: string | null; supplier?: string | null; supplierId?: string | null; otherProperty?: Record<string, any> } |
Returns
Promise<IPCB_PrimitiveComponent | undefined>
Device primitive object
Example
javascript
// 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());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25