Home > PCB_PrimitiveComponent > delete
PCB_PrimitiveComponent.delete() 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.
Delete Device
Signature
typescript
function delete(primitiveIds: string | IPCB_PrimitiveComponent | Array<string> | Array<IPCB_PrimitiveComponent>): Promise<boolean>;1
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveIds | string | IPCB_PrimitiveComponent | Array<string> | Array<IPCB_PrimitiveComponent> | Device primitive ID or Device primitive object |
Returns
Promise<boolean>
Delete Whether the operation is successful
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. 记录删除前的器件图元 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