Home > PCB_Primitive > getPrimitiveBoardLine
PCB_Primitive.getPrimitiveBoardLine() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
获取图元的边框线
签名
typescript
function getPrimitiveBoardLine(
primitiveId: string,
layers?: Array<EPCB_LayerId>,
): Promise<IPCB_ComplexPolygon | undefined>;1
2
3
4
2
3
4
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveId | string | 图元 ID |
layers | Array<EPCB_LayerId> | (可选) 需要计算的层,在计算器件、焊盘、过孔时能够精确计算指定多个层的边框线的并集 |
返回值
Promise<IPCB_ComplexPolygon | undefined>
复杂多边形,如果图元 ID 未匹配或图元在指定层上不存在,则返回 undefined
示例
javascript
// 1. 创建顶层圆形焊盘作为测试图元
const pad = await eda.pcb_PrimitivePad.create(1, '1', 2000, 2000, 0, ['ELLIPSE', 80, 80], '', null, 0, 0, 0, false, 0);
const primitiveId = pad.getState_PrimitiveId();
// 2. 计算边框线:文档签名为同步返回,实测返回 Promise(第二参数可指定参与计算的层)
const pending = eda.pcb_Primitive.getPrimitiveBoardLine(primitiveId, [1]);
// 3. 等待 3 秒观察结果状态(当前版本 Promise 不 settle,用超时保护避免卡住)
const settled = await Promise.race([
Promise.resolve(pending).then(() => 'fulfilled', () => 'rejected'),
new Promise(resolve => setTimeout(() => resolve('pending(3 秒内未返回)'), 3000)),
]);
// 4. 清理测试图元(查询类需要清理)
await eda.pcb_PrimitivePad.delete([primitiveId]);
console.log('primitiveId:', primitiveId);
console.log('returns:', typeof pending.then === 'function' ? 'Promise' : typeof pending);
console.log('settled:', settled);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19