Home > PCB_PrimitiveComponent > delete
PCB_PrimitiveComponent.delete() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
删除器件
签名
typescript
function delete(primitiveIds: string | IPCB_PrimitiveComponent | Array<string> | Array<IPCB_PrimitiveComponent>): Promise<boolean>;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveIds | string | IPCB_PrimitiveComponent | Array<string> | Array<IPCB_PrimitiveComponent> | 器件的图元 ID 或器件图元对象 |
返回值
Promise<boolean>
删除操作是否成功
示例
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. 记录删除前的器件图元 ID 列表
const beforeIds = await eda.pcb_PrimitiveComponent.getAllPrimitiveId();
const beforeContains = beforeIds.includes(compId);
// 3. 以 ID 数组形式删除该器件
const deleted = await eda.pcb_PrimitiveComponent.delete([compId]);
// 4. 验证删除后 ID 列表不再包含该器件
const afterIds = await eda.pcb_PrimitiveComponent.getAllPrimitiveId();
console.log('deleted:', deleted);
console.log('beforeContains:', beforeContains);
console.log('afterContains:', afterIds.includes(compId));
console.log('component count:', beforeIds.length, '→', afterIds.length);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23