Home > SCH_PrimitiveRectangle > modify
SCH_PrimitiveRectangle.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改矩形
签名
function modify(
primitiveId: string | ISCH_PrimitiveRectangle,
property: {
topLeftX?: undefined | number;
topLeftY?: undefined | number;
width?: undefined | number;
height?: undefined | number;
cornerRadius?: undefined | number;
rotation?: undefined | number;
color?: undefined | null | string;
fillColor?: undefined | null | string;
lineWidth?: undefined | null | number;
lineType?:
| undefined
| null
| ESCH_PrimitiveLineType.SOLID
| ESCH_PrimitiveLineType.DASHED
| ESCH_PrimitiveLineType.DOTTED
| ESCH_PrimitiveLineType.DOT_DASHED;
fillStyle?:
| undefined
| null
| ESCH_PrimitiveFillStyle.NONE
| ESCH_PrimitiveFillStyle.SOLID
| ESCH_PrimitiveFillStyle.GRID
| ESCH_PrimitiveFillStyle.HORIZONTAL_LINE
| ESCH_PrimitiveFillStyle.VERTICAL_LINE
| ESCH_PrimitiveFillStyle.RHOMBIC_GRID
| ESCH_PrimitiveFillStyle.LEFT_SLASH_LINE
| ESCH_PrimitiveFillStyle.RIGHT_SLASH_LINE;
},
): Promise<ISCH_PrimitiveRectangle | undefined>;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
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveId | string | ISCH_PrimitiveRectangle | 图元 ID |
property | { topLeftX?: undefined | number; topLeftY?: undefined | number; width?: undefined | number; height?: undefined | number; cornerRadius?: undefined | number; rotation?: undefined | number; color?: undefined | null | string; fillColor?: undefined | null | string; lineWidth?: undefined | null | number; lineType?: undefined | null | ESCH_PrimitiveLineType.SOLID | ESCH_PrimitiveLineType.DASHED | ESCH_PrimitiveLineType.DOTTED | ESCH_PrimitiveLineType.DOT_DASHED; fillStyle?: undefined | null | ESCH_PrimitiveFillStyle.NONE | ESCH_PrimitiveFillStyle.SOLID | ESCH_PrimitiveFillStyle.GRID | ESCH_PrimitiveFillStyle.HORIZONTAL_LINE | ESCH_PrimitiveFillStyle.VERTICAL_LINE | ESCH_PrimitiveFillStyle.RHOMBIC_GRID | ESCH_PrimitiveFillStyle.LEFT_SLASH_LINE | ESCH_PrimitiveFillStyle.RIGHT_SLASH_LINE } | 修改参数 |
返回值
Promise<ISCH_PrimitiveRectangle | undefined>
矩形图元对象
示例
// 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());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