Home > SCH_PrimitiveComponent > create
SCH_PrimitiveComponent.create() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
创建器件
签名
typescript
function create(
component:
| { libraryType?: undefined | ELIB_LibraryType.DEVICE; libraryUuid: string; uuid: string }
| ILIB_DeviceItem
| ILIB_DeviceSearchItem
| { libraryType: ELIB_LibraryType.SYMBOL; libraryUuid: string; uuid: string }
| ILIB_SymbolItem
| ILIB_SymbolSearchItem,
x: number,
y: number,
subPartName?: string,
rotation?: number,
mirror?: boolean,
addIntoBom?: boolean,
addIntoPcb?: boolean,
): Promise<ISCH_PrimitiveComponent | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
参数名
参数 | 类型 | 描述 |
|---|---|---|
component | { libraryType?: undefined | ELIB_LibraryType.DEVICE; libraryUuid: string; uuid: string } | ILIB_DeviceItem | ILIB_DeviceSearchItem | { libraryType: ELIB_LibraryType.SYMBOL; libraryUuid: string; uuid: string } | ILIB_SymbolItem | ILIB_SymbolSearchItem | 关联库器件 |
x | number | 坐标 X |
y | number | 坐标 Y |
subPartName | string | (可选) 子部件名称 |
rotation | number | (可选) 旋转角度 |
mirror | boolean | (可选) 是否镜像 |
addIntoBom | boolean | (可选) 是否加入 BOM |
addIntoPcb | boolean | (可选) 是否转到 PCB |
返回值
Promise<ISCH_PrimitiveComponent | undefined>
器件图元对象
示例
javascript
// 1. 从系统库搜索器件,随机坐标避免与画布已有器件重合(SCH 坐标单位 10mil)
const devices = await eda.lib_Device.search('');
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
// 2. 创建器件:搜索结果直接作为关联库器件传入,加入 BOM 并转到 PCB
const comp = await eda.sch_PrimitiveComponent.create(
devices[0], // 关联库器件
x, // 坐标 X
y, // 坐标 Y
undefined, // 子部件名称(多子部件器件才需要指定)
0, // 旋转角度
false, // 是否镜像
true, // 是否加入 BOM
true // 是否转到 PCB
);
// 3. 创建类保留现场,供在画布上观察摆放结果
console.log('primitiveId:', comp.getState_PrimitiveId());
console.log('designator:', comp.getState_Designator());
console.log('position:', comp.getState_X(), ',', comp.getState_Y());
console.log('addIntoBom:', comp.getState_AddIntoBom());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22