Home > PCB_Document > getPrimitivesInRegion
PCB_Document.getPrimitivesInRegion() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
获取区域内所有图元
签名
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
参数名
参数 | 类型 | 描述 |
|---|---|---|
left | number | 矩形框第一 X 坐标 |
right | number | 矩形框第二 X 坐标 |
top | number | 矩形框第一 Y 坐标 |
bottom | number | 矩形框第二 Y 坐标 |
leftToRight | boolean | (可选) 是否仅获取完全框选的图元, |
返回值
Promise<Array<IPCB_Primitive>>
区域内所有图元
示例
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