Home > PCB_PrimitiveRegion > modify
PCB_PrimitiveRegion.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改区域
签名
typescript
function modify(
primitiveId: string | IPCB_PrimitiveRegion,
property: {
layer?:
| undefined
| EPCB_LayerId.TOP
| EPCB_LayerId.BOTTOM
| EPCB_LayerId.MULTI
| EPCB_LayerId.INNER_1
| EPCB_LayerId.INNER_2
| EPCB_LayerId.INNER_3
| EPCB_LayerId.INNER_4
| EPCB_LayerId.INNER_5
| EPCB_LayerId.INNER_6
| EPCB_LayerId.INNER_7
| EPCB_LayerId.INNER_8
| EPCB_LayerId.INNER_9
| EPCB_LayerId.INNER_10
| EPCB_LayerId.INNER_11
| EPCB_LayerId.INNER_12
| EPCB_LayerId.INNER_13
| EPCB_LayerId.INNER_14
| EPCB_LayerId.INNER_15
| EPCB_LayerId.INNER_16
| EPCB_LayerId.INNER_17
| EPCB_LayerId.INNER_18
| EPCB_LayerId.INNER_19
| EPCB_LayerId.INNER_20
| EPCB_LayerId.INNER_21
| EPCB_LayerId.INNER_22
| EPCB_LayerId.INNER_23
| EPCB_LayerId.INNER_24
| EPCB_LayerId.INNER_25
| EPCB_LayerId.INNER_26
| EPCB_LayerId.INNER_27
| EPCB_LayerId.INNER_28
| EPCB_LayerId.INNER_29
| EPCB_LayerId.INNER_30;
complexPolygon?: undefined | IPCB_Polygon;
ruleType?: undefined | EPCB_PrimitiveRegionRuleType[];
regionName?: undefined | string;
lineWidth?: undefined | number;
primitiveLock?: undefined | false | true;
},
): Promise<IPCB_PrimitiveRegion | undefined>;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
33
34
35
36
37
38
39
40
41
42
43
44
45
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
33
34
35
36
37
38
39
40
41
42
43
44
45
参数名
返回值
Promise<IPCB_PrimitiveRegion | undefined>
区域图元对象,undefined 表示修改失败
示例
javascript
// 1. 创建待修改的测试区域:顶层,规则 [2] 即禁止元件(随机坐标避免重合)
const x = 2000 + Math.floor(Math.random() * 100000);
const y = 2000 + Math.floor(Math.random() * 100000);
const polygon = eda.pcb_MathPolygon.createPolygon(['R', x, y, 500, 300, 0, 0]);
const region = await eda.pcb_PrimitiveRegion.create(1, polygon, [2], '嘉立创示例_待修改');
const regionId = region.getState_PrimitiveId();
// 2. 读取修改前的层与规则类型
const beforeLayer = region.getState_Layer();
const beforeRuleType = region.getState_RuleType();
// 3. 批量修改:层从顶层(1)换到底层(2),规则 [2] 禁止元件扩展为 [2, 5] 禁止元件 + 禁止布线
await eda.pcb_PrimitiveRegion.modify(regionId, { layer: 2, ruleType: [2, 5] });
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.pcb_PrimitiveRegion.get(regionId);
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', regionId);
console.log('layer:', beforeLayer, '→', refreshed.getState_Layer());
console.log('ruleType:', JSON.stringify(beforeRuleType), '→', JSON.stringify(refreshed.getState_RuleType()));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21