Home > SCH_PrimitiveText > create
SCH_PrimitiveText.create() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
创建文本
签名
typescript
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>;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
参数名
参数 | 类型 | 描述 |
|---|---|---|
x | number | 坐标 X |
y | number | 坐标 Y |
content | string | 文本内容 |
rotation | number | (可选) 旋转角度,可选 |
textColor | string | null | (可选) 文本颜色, |
fontName | string | null | (可选) 字体名称, |
fontSize | number | null | (可选) 字体大小, |
bold | boolean | (可选) 是否加粗 |
italic | boolean | (可选) 是否斜体 |
underLine | boolean | (可选) 是否加下划线 |
alignMode | (可选) 对齐模式 |
返回值
Promise<ISCH_PrimitiveText | undefined>
文本图元对象
示例
javascript
// 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());1
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
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