Home > PCB_Document > getPrimitiveAtPoint
PCB_Document.getPrimitiveAtPoint() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
获取坐标点的图元
签名
typescript
function getPrimitiveAtPoint(x: number, y: number): Promise<IPCB_Primitive | undefined>;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
x | number | 坐标点 X |
y | number | 坐标点 Y |
返回值
Promise<IPCB_Primitive | undefined>
坐标点的图元,如若坐标点无法找到图元,将返回 undefined
备注
本操作和前端鼠标点击操作类似,将会获取指定坐标点上的图元
示例
javascript
// 1. 创建测试 PCB 并打开
const pcbUuid = await eda.dmt_Pcb.createPcb();
await new Promise(r => setTimeout(r, 1500));
await eda.dmt_EditorControl.openDocument(pcbUuid);
await new Promise(r => setTimeout(r, 1000));
// 2. 在 (500, 500) 放一个测试焊盘作为拾取目标
const pad = await eda.pcb_PrimitivePad.create(1, '1', 500, 500, 0, ['ELLIPSE', 60, 60], '', null, 0, 0, 0, false, 0);
const padId = pad.getState_PrimitiveId();
// 3. 拾取焊盘中心点,返回该焊盘图元
const hit = await eda.pcb_Document.getPrimitiveAtPoint(500, 500);
console.log('hitPrimitiveId:', hit.getState_PrimitiveId());
// 4. 拾取空白坐标点,返回 undefined
const miss = await eda.pcb_Document.getPrimitiveAtPoint(90000, 90000);
console.log('空白坐标点:', miss === undefined ? '未找到图元' : '找到图元');
// 5. 清理测试图元和测试 PCB
await eda.pcb_PrimitivePad.delete([padId]);
await eda.dmt_Pcb.deletePcb(pcbUuid);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21