Home > PCB_Document > getPrimitivesInRegion
PCB_Document.getPrimitivesInRegion() 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 All primitives in the region
Signature
typescript
function getPrimitivesInRegion(
left: number,
right: number,
top: number,
bottom: number,
leftToRight?: boolean,
): Promise<Array<IPCB_Primitive>>;1
2
3
4
5
6
7
2
3
4
5
6
7
Parameters
Parameter | Type | Description |
|---|---|---|
left | number | First X coordinate of the rectangle |
right | number | Second X coordinate of the rectangle |
top | number | First Y coordinate of the rectangle |
bottom | number | Second Y coordinate of the rectangle |
leftToRight | boolean | (Optional) Whether to only get primitives that are fully enclosed by the box selection. If |
Returns
Promise<Array<IPCB_Primitive>>
All primitives in the region
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),一个在 (3000, 3000)
const padA = await eda.pcb_PrimitivePad.create(1, '1', 500, 500, 0, ['ELLIPSE', 60, 60], '', null, 0, 0, 0, false, 0);
const padB = await eda.pcb_PrimitivePad.create(1, '2', 3000, 3000, 0, ['ELLIPSE', 60, 60], '', null, 0, 0, 0, false, 0);
// 3. 小区域 (0,1000,1000,0) 只盖住第一个焊盘
const small = await eda.pcb_Document.getPrimitivesInRegion(0, 1000, 1000, 0);
console.log('smallRegionCount:', small.length);
// 4. 大区域 (0,4000,4000,0) 盖住两个焊盘,完全框选模式
const big = await eda.pcb_Document.getPrimitivesInRegion(0, 4000, 4000, 0, true);
console.log('bigRegionCount:', big.length);
// 5. 清理测试图元和测试 PCB
await eda.pcb_PrimitivePad.delete([padA.getState_PrimitiveId(), padB.getState_PrimitiveId()]);
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