Home > PCB_PrimitiveString > create
PCB_PrimitiveString.create() 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.
Create Text
Signature
typescript
function create(
layer: TPCB_LayersOfImage,
x: number,
y: number,
text: string,
fontFamily: string,
fontSize: number,
lineWidth: number,
alignMode: EPCB_PrimitiveStringAlignMode,
rotation: number,
reverse: boolean,
expansion: number,
mirror: boolean,
primitiveLock: boolean,
): Promise<IPCB_PrimitiveString | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Parameters
Parameter | Type | Description |
|---|---|---|
layer | Layer | |
x | number | X coordinate |
y | number | Y coordinate |
text | string | Text content |
fontFamily | string | Font. It needs to be imported into EasyEDA in advance |
fontSize | number | Font size |
lineWidth | number | Line width |
alignMode | Alignment mode | |
rotation | number | Rotation angle |
reverse | boolean | Whether it is inverted |
expansion | number | Inverted expansion |
mirror | boolean | Whether it is mirrored |
primitiveLock | boolean | Whether it is locked |
Returns
Promise<IPCB_PrimitiveString | undefined>
Text primitive object
Example
javascript
// 1. 生成随机放置坐标,避免与画布上已有的文本重合
const x = 2000 + Math.floor(Math.random() * 100000);
const y = 2000 + Math.floor(Math.random() * 100000);
// 2. 在顶层丝印层(3)创建文本:默认字体、字号 45、线宽 6、左下对齐(3)、不旋转、不反相、不镜像、不锁定
const text = await eda.pcb_PrimitiveString.create(3, x, y, '嘉立创示例_版本V1.0', 'default', 45, 6, 3, 0, false, 0, false, false);
// 3. 创建类保留现场,不删除图元
console.log('primitiveId:', text.getState_PrimitiveId());
console.log('primitiveType:', text.getState_PrimitiveType());
console.log('layer:', text.getState_Layer());
console.log('text:', text.getState_Text());
console.log('fontSize:', text.getState_FontSize());1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13