Home > SCH_PrimitiveRectangle > modify
SCH_PrimitiveRectangle.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 Rectangle
Signature
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
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | ISCH_PrimitiveRectangle | Primitive 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 } | Modify Parameter |
Returns
Promise<ISCH_PrimitiveRectangle | undefined>
Rectangle primitive object
Example
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