Home > SCH_PrimitivePolygon > modify
SCH_PrimitivePolygon.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改多边形
签名
typescript
function modify(
primitiveId: string | ISCH_PrimitivePolygon,
property: {
line?: 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;
},
): Promise<ISCH_PrimitivePolygon | 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_PrimitivePolygon | 图元 ID |
property | { line?: 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 } | 修改参数 |
返回值
Promise<ISCH_PrimitivePolygon | undefined>
多边形图元对象
示例
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