Home > SCH_PrimitiveAttribute > getAllPrimitiveId
SCH_PrimitiveAttribute.getAllPrimitiveId() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
获取所有属性的图元 ID
签名
typescript
function getAllPrimitiveId(parentPrimitiveId?: string): Promise<Array<string>>;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
parentPrimitiveId | string | (可选) 父图元 ID |
返回值
Promise<Array<string>>
属性的图元 ID 数组
备注
不传递父图元 ID 将拿到图页中的所有属性图元
示例
javascript
// 1. 放置一个测试器件(属性图元随器件生成,无法单独创建)
const devices = await eda.lib_Device.search('');
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
const comp = await eda.sch_PrimitiveComponent.create(devices[0], x, y);
const compId = comp.getState_PrimitiveId();
// 2. 传父图元 ID,只拿该器件的属性图元 ID
const compAttrIds = await eda.sch_PrimitiveAttribute.getAllPrimitiveId(compId);
// 3. 不传参数,拿当前图页全部属性图元 ID(含器件属性与独立网络标签等)
const allIds = await eda.sch_PrimitiveAttribute.getAllPrimitiveId();
// 4. 清理测试器件(属性图元随器件一起删除)
await eda.sch_PrimitiveComponent.delete([compId]);
console.log('component attr ids:', compAttrIds.length);
console.log('page total attr ids:', allIds.length);
console.log('component ids all in page list:', compAttrIds.every(id => allIds.includes(id)));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