Home > PCB_Document > getPrimitiveAtPoint
PCB_Document.getPrimitiveAtPoint() 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.
Get The primitive at the coordinate point
Signature
typescript
function getPrimitiveAtPoint(x: number, y: number): Promise<IPCB_Primitive | undefined>;1
Parameters
Parameter | Type | Description |
|---|---|---|
x | number | Coordinate point X |
y | number | Coordinate point Y |
Returns
Promise<IPCB_Primitive | undefined>
The primitive at the coordinate point. If no primitive can be found at the coordinate point, undefined will be returned
Remarks
This operation is similar to clicking with the mouse on the front end; it will get the primitive at the specified coordinate point
Example
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