Home > PCB_PrimitiveAttribute > delete
PCB_PrimitiveAttribute.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 Property
Signature
typescript
function delete(primitiveIds: string | IPCB_PrimitiveAttribute | Array<string> | Array<IPCB_PrimitiveAttribute>): Promise<boolean>;1
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveIds | string | IPCB_PrimitiveAttribute | Array<string> | Array<IPCB_PrimitiveAttribute> | Property primitive ID or Text 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. 给器件添加一条自定义属性作为删除目标
await comp.setAttribute('嘉立创示例_Tolerance', '1%', true, true);
// 3. 找到自定义属性的图元并记录删除前的属性数量
const attrIds = await eda.pcb_PrimitiveAttribute.getAllPrimitiveId(compId);
const attrs = await eda.pcb_PrimitiveAttribute.get(attrIds);
const target = attrs.find(a => a.getState_Key() === '嘉立创示例_Tolerance');
const beforeCount = attrs.length;
// 4. 以 ID 字符串形式删除该属性
const deleted = await eda.pcb_PrimitiveAttribute.delete(target.getState_PrimitiveId());
// 5. 删除类保留现场(器件留在画布上,属性已删除)
const afterCount = (await eda.pcb_PrimitiveAttribute.getAllPrimitiveId(compId)).length;
console.log('deleted:', deleted);
console.log('attribute count:', beforeCount, '→', afterCount);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
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26