Home > PCB_PrimitiveComponent > create
PCB_PrimitiveComponent.create() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
创建器件
签名
typescript
function create(
component:
| { libraryUuid: string; uuid: string }
| ILIB_DeviceItem
| ILIB_DeviceSearchItem
| { libraryType: ELIB_LibraryType.FOOTPRINT; libraryUuid: string; uuid: string }
| ILIB_FootprintItem
| ILIB_FootprintSearchItem,
layer: TPCB_LayersOfComponent,
x: number,
y: number,
rotation?: number,
primitiveLock?: boolean,
): Promise<IPCB_PrimitiveComponent | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
参数名
参数 | 类型 | 描述 |
|---|---|---|
component | { libraryUuid: string; uuid: string } | ILIB_DeviceItem | ILIB_DeviceSearchItem | { libraryType: ELIB_LibraryType.FOOTPRINT; libraryUuid: string; uuid: string } | ILIB_FootprintItem | ILIB_FootprintSearchItem | 关联库器件 |
layer | 层 | |
x | number | 坐标 X |
y | number | 坐标 Y |
rotation | number | (可选) 旋转角度 |
primitiveLock | boolean | (可选) 是否锁定 |
返回值
Promise<IPCB_PrimitiveComponent | undefined>
器件图元对象
示例
javascript
// 1. 按立创编号从系统库精确反查器件,返回项不含 libraryUuid,需补上才能用于 create
// 坐标取随机值,避免与画布上已有的器件重合
const x = 20000 + Math.floor(Math.random() * 80000);
const y = 20000 + Math.floor(Math.random() * 80000);
const devices = await eda.lib_Device.searchByProperties({ supplierId: 'C1523' }, undefined, undefined, undefined, 5, 1);
const sysLibUuid = await eda.lib_LibrariesList.getSystemLibraryUuid();
// 2. 放置到顶层(1),旋转 90°,不锁定
const comp = await eda.pcb_PrimitiveComponent.create({ libraryUuid: sysLibUuid, uuid: devices[0].uuid }, 1, x, y, 90, false);
// 3. 创建类保留现场,不删除器件
console.log('primitiveId:', comp.getState_PrimitiveId());
console.log('designator:', comp.getState_Designator());
console.log('name:', comp.getState_Name());
console.log('footprint:', comp.getState_Footprint());
console.log('layer:', comp.getState_Layer());
console.log('x:', comp.getState_X(), 'y:', comp.getState_Y());
console.log('rotation:', comp.getState_Rotation());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18