Home > PCB_PrimitiveObject > modify
PCB_PrimitiveObject.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改二进制内嵌对象
签名
typescript
function modify(
primitiveId: string | IPCB_PrimitiveObject,
property: {
layer?:
| undefined
| EPCB_LayerId.TOP_SILKSCREEN
| EPCB_LayerId.BOTTOM_SILKSCREEN
| EPCB_LayerId.DOCUMENT;
topLeftX?: undefined | number;
topLeftY?: undefined | number;
binaryData?: undefined | string;
width?: undefined | number;
height?: undefined | number;
rotation?: undefined | number;
mirror?: undefined | false | true;
fileName?: undefined | string;
primitiveLock?: undefined | false | true;
},
): Promise<IPCB_PrimitiveObject | 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
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveId | string | IPCB_PrimitiveObject | 图元 ID |
property | { layer?: undefined | EPCB_LayerId.TOP_SILKSCREEN | EPCB_LayerId.BOTTOM_SILKSCREEN | EPCB_LayerId.DOCUMENT; topLeftX?: undefined | number; topLeftY?: undefined | number; binaryData?: undefined | string; width?: undefined | number; height?: undefined | number; rotation?: undefined | number; mirror?: undefined | false | true; fileName?: undefined | string; primitiveLock?: undefined | false | true } | 修改参数 |
返回值
Promise<IPCB_PrimitiveObject | undefined>
二进制内嵌对象图元对象,undefined 表示修改失败
示例
javascript
// 1. 创建待修改的测试内嵌对象(随机坐标避免重合),使用 4x4 像素 PNG 的 data URI
const x = 2000 + Math.floor(Math.random() * 100000);
const y = 2000 + Math.floor(Math.random() * 100000);
const binaryData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAEElEQVR4nGP4z8AARwzEcQCukw/x0F8jngAAAABJRU5ErkJggg==';
const obj = await eda.pcb_PrimitiveObject.create(3, x, y, binaryData, 400, 300, 0, false, 'logo.png', false);
const objId = obj.getState_PrimitiveId();
// 2. 读取修改前的宽与旋转角
const beforeWidth = obj.getState_Width();
const beforeRotation = obj.getState_Rotation();
// 3. 批量修改:宽 400 → 500,旋转 0 → 90 度
await eda.pcb_PrimitiveObject.modify(objId, { width: 500, rotation: 90 });
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.pcb_PrimitiveObject.get(objId);
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', objId);
console.log('width:', beforeWidth, '→', refreshed.getState_Width());
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21