Home > SCH_PrimitiveComponent > getAll
SCH_PrimitiveComponent.getAll() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
获取所有器件
签名
typescript
function getAll(
componentType?: ESCH_PrimitiveComponentType,
allSchematicPages?: boolean,
): Promise<Array<ISCH_PrimitiveComponent>>;1
2
3
4
2
3
4
参数名
参数 | 类型 | 描述 |
|---|---|---|
componentType | (可选) 器件类型 | |
allSchematicPages | boolean | (可选) 是否获取所有原理图图页的器件 |
返回值
Promise<Array<ISCH_PrimitiveComponent>>
器件图元对象数组
示例
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 flag = await eda.sch_PrimitiveComponent.createNetFlag('Power', '嘉立创示例_VCC', x + 600, y);
const compId = comp.getState_PrimitiveId();
// 2. 不传参数,取当前图页全部器件
const all = await eda.sch_PrimitiveComponent.getAll();
// 3. 传入类型 'netflag' 只取网络标识(ESCH_PrimitiveComponentType 值)
const flags = await eda.sch_PrimitiveComponent.getAll('netflag');
// 4. 清理测试图元(查询类需要清理)
await eda.sch_PrimitiveComponent.delete([compId, flag.getState_PrimitiveId()]);
console.log('total components:', all.length);
console.log('marker comp found:', all.some(c => c.getState_PrimitiveId() === compId));
console.log('netflag count:', flags.length);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20