Home > SCH_PrimitiveText > create
SCH_PrimitiveText.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
function create(
x: number,
y: number,
content: string,
rotation?: number,
textColor?: string | null,
fontName?: string | null,
fontSize?: number | null,
bold?: boolean,
italic?: boolean,
underLine?: boolean,
alignMode?: ESCH_PrimitiveTextAlignMode,
): Promise<ISCH_PrimitiveText | undefined>;2
3
4
5
6
7
8
9
10
11
12
13
Parameters
Parameter | Type | Description |
|---|---|---|
x | number | X coordinate |
y | number | Y coordinate |
content | string | Text content |
rotation | number | (Optional) Rotation angle. Options: |
textColor | string | null | (Optional) Text color, |
fontName | string | null | (Optional) Font name, |
fontSize | number | null | (Optional) Font size. |
bold | boolean | (Optional) Whether it is bold |
italic | boolean | (Optional) Whether it is italic |
underLine | boolean | (Optional) Whether it is underlined |
alignMode | (Optional) Alignment mode |
Returns
Promise<ISCH_PrimitiveText | undefined>
Text primitive object
Example
// 1. 生成随机坐标,避免与画布上已有的文本重合(SCH 坐标单位 10mil)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
// 2. 创建一段完整样式的文本:旋转 90 度、红色、Arial 字体、字号 20、加粗、带下划线、居中对齐(CENTER = 5)
const text = await eda.sch_PrimitiveText.create(
x,
y,
'嘉立创示例_设计说明',
90,
'#FF0000',
'Arial',
20,
true,
false,
true,
5
);
// 3. 创建类保留现场,不删除图元;读回各属性确认样式已生效
console.log('primitiveId:', text.getState_PrimitiveId());
console.log('primitiveType:', text.getState_PrimitiveType());
console.log('position:', text.getState_X(), text.getState_Y());
console.log('content:', text.getState_Content());
console.log('rotation:', text.getState_Rotation());
console.log('textColor:', text.getState_TextColor());
console.log('fontName:', text.getState_FontName());
console.log('fontSize:', text.getState_FontSize());
console.log('bold:', text.getState_Bold());
console.log('italic:', text.getState_Italic());
console.log('underLine:', text.getState_UnderLine());
console.log('alignMode:', text.getState_AlignMode());2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32