Home > SCH_PrimitivePolygon > modify
SCH_PrimitivePolygon.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 Polygon
Signature
typescript
function modify(
primitiveId: string | ISCH_PrimitivePolygon,
property: {
line?: Array<number>;
color?: string | null;
fillColor?: string | null;
lineWidth?: number | null;
lineType?: ESCH_PrimitiveLineType | null;
},
): Promise<ISCH_PrimitivePolygon | undefined>;1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | ISCH_PrimitivePolygon | Primitive ID |
property | { line?: Array<number>; color?: string | null; fillColor?: string | null; lineWidth?: number | null; lineType?: ESCH_PrimitiveLineType | null } | Modify Parameter |
Returns
Promise<ISCH_PrimitivePolygon | undefined>
Polygon primitive object
Example
javascript
// 1. 创建待修改的测试多边形:4 顶点矩形、红色边线、黄色填充(随机坐标避免重合)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
const rect = [x, y, x + 400, y, x + 400, y + 300, x, y + 300];
const polygon = await eda.sch_PrimitivePolygon.create(rect, '#FF0000', '#FFFF00', 6, 1);
const polygonId = polygon.getState_PrimitiveId();
// 2. 记录修改前的线宽、颜色与填充色
const beforeWidth = polygon.getState_LineWidth();
const beforeColor = polygon.getState_Color();
const beforeFill = polygon.getState_FillColor();
// 3. 批量修改:形状整体替换为 3 顶点三角形、线宽 6 → 10、边线改绿色、填充改无色
const triangle = [x, y, x + 400, y, x + 200, y + 350];
await eda.sch_PrimitivePolygon.modify(polygonId, { line: triangle, lineWidth: 10, color: '#00AA00', fillColor: 'none' });
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.sch_PrimitivePolygon.get(polygonId);
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', polygonId);
console.log('lineWidth:', beforeWidth, '→', refreshed.getState_LineWidth());
console.log('color:', beforeColor, '→', refreshed.getState_Color());
console.log('fillColor:', beforeFill, '→', refreshed.getState_FillColor());
console.log('line:', JSON.stringify(rect), '→', JSON.stringify(refreshed.getState_Line()));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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25