Home > SCH_PrimitiveText > modify
SCH_PrimitiveText.modify() 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.
Modify Text
Signature
typescript
function modify(
primitiveId: string | ISCH_PrimitiveText,
property: {
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
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | ISCH_PrimitiveText | Primitive ID |
property | { 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 } | Modify Parameter |
Returns
Promise<ISCH_PrimitiveText | undefined>
Text primitive object
Example
javascript
// 1. 创建待修改的测试文本:默认样式(随机坐标避免重合)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
const text = await eda.sch_PrimitiveText.create(x, y, '嘉立创示例_原始文本');
const textId = text.getState_PrimitiveId();
// 2. 记录修改前的内容、颜色与字号
const beforeContent = text.getState_Content();
const beforeColor = text.getState_TextColor();
const beforeFontSize = text.getState_FontSize();
// 3. 批量修改:平移位置、内容更新、颜色改蓝、字号 20、加粗
await eda.sch_PrimitiveText.modify(textId, {
x: x + 200,
y: y + 100,
content: '嘉立创示例_修改后的文本',
textColor: '#0000FF',
fontSize: 20,
bold: true,
});
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.sch_PrimitiveText.get(textId);
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', textId);
console.log('content:', beforeContent, '→', refreshed.getState_Content());
console.log('textColor:', beforeColor, '→', refreshed.getState_TextColor());
console.log('fontSize:', beforeFontSize, '→', refreshed.getState_FontSize());
console.log('bold:', refreshed.getState_Bold());
console.log('position:', x, y, '→', refreshed.getState_X(), refreshed.getState_Y());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
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