Home > IPCB_PrimitiveComponentPad > getConnectedPrimitives
IPCB_PrimitiveComponentPad.getConnectedPrimitives() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
获取连接的图元
签名
typescript
function getConnectedPrimitives(
onlyCentreConnection: true,
): Promise<Array<IPCB_PrimitiveLine | IPCB_PrimitiveArc | IPCB_PrimitiveVia>>;1
2
3
2
3
参数名
参数 | 类型 | 描述 |
|---|---|---|
onlyCentreConnection | true | 是否仅中心连接,如若为 |
返回值
Promise<Array<IPCB_PrimitiveLine | IPCB_PrimitiveArc | IPCB_PrimitiveVia>>
备注
本接口可以获取到与焊盘直接接触的图元
示例
javascript
// 1. 放置测试器件,取第一个焊盘的中心坐标
const devices = await eda.lib_Device.search('C0402');
const comp = await eda.pcb_PrimitiveComponent.create(devices[0], 1, 5000, 5000);
const compId = comp.getState_PrimitiveId();
const pin = (await comp.getAllPins())[0];
const padX = pin.getState_X();
const padY = pin.getState_Y();
// 2. 从焊盘中心拉一段走线(起点正好落在中心 → 属于中心连接)
const line = await eda.pcb_PrimitiveLine.create('', 1, padX, padY, padX + 600, padY, 10);
const lineId = line.getState_PrimitiveId();
// 3. 只查中心连接的图元
const centreConnected = await pin.getConnectedPrimitives(true);
// 4. 查所有接触的图元
const allConnected = await pin.getConnectedPrimitives(false);
// 5. 清理测试图元
await eda.pcb_PrimitiveLine.delete([lineId]);
await eda.pcb_PrimitiveComponent.delete([compId]);
console.log('centreConnectedCount:', centreConnected.length);
console.log('centreContainsLine:', centreConnected.some(p => p.getState_PrimitiveId() === lineId));
console.log('allConnectedCount:', allConnected.length);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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25