Home > SCH_PrimitiveRectangle > modify
SCH_PrimitiveRectangle.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改矩形
签名
typescript
function modify(
primitiveId: string | ISCH_PrimitiveRectangle,
property: {
topLeftX?: number;
topLeftY?: number;
width?: number;
height?: number;
cornerRadius?: number;
rotation?: number;
color?: string | null;
fillColor?: string | null;
lineWidth?: number | null;
lineType?: ESCH_PrimitiveLineType | null;
fillStyle?: ESCH_PrimitiveFillStyle | null;
},
): Promise<ISCH_PrimitiveRectangle | 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
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveId | string | ISCH_PrimitiveRectangle | 图元 ID |
property | { topLeftX?: number; topLeftY?: number; width?: number; height?: number; cornerRadius?: number; rotation?: number; color?: string | null; fillColor?: string | null; lineWidth?: number | null; lineType?: ESCH_PrimitiveLineType | null; fillStyle?: ESCH_PrimitiveFillStyle | null } | 修改参数 |
返回值
Promise<ISCH_PrimitiveRectangle | undefined>
矩形图元对象
示例
javascript
// 1. 创建待修改的测试矩形:宽 400 高 300 直角、红色边线(随机坐标避免重合)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
const rect = await eda.sch_PrimitiveRectangle.create(x, y, 400, 300, 0, 0, '#FF0000');
const rectId = rect.getState_PrimitiveId();
// 2. 记录修改前的尺寸、圆角与颜色
const beforeWidth = rect.getState_Width();
const beforeRadius = rect.getState_CornerRadius();
const beforeColor = rect.getState_Color();
// 3. 批量修改:左上角平移、宽 400 → 600、直角 → 圆角 40、边线改绿色、填充改蓝色实心
await eda.sch_PrimitiveRectangle.modify(rectId, {
topLeftX: x + 200,
topLeftY: y + 100,
width: 600,
cornerRadius: 40,
color: '#00AA00',
fillColor: '#0000FF',
fillStyle: 'Solid',
});
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.sch_PrimitiveRectangle.get(rectId);
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', rectId);
console.log('width:', beforeWidth, '→', refreshed.getState_Width());
console.log('cornerRadius:', beforeRadius, '→', refreshed.getState_CornerRadius());
console.log('color:', beforeColor, '→', refreshed.getState_Color());
console.log('topLeft:', x, y, '→', refreshed.getState_TopLeftX(), refreshed.getState_TopLeftY());
console.log('fillStyle:', refreshed.getState_FillStyle());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