Home > PCB_PrimitiveRegion > modify
PCB_PrimitiveRegion.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 Region
Signature
typescript
function modify(
primitiveId: string | IPCB_PrimitiveRegion,
property: {
layer?: TPCB_LayersOfRegion;
complexPolygon?: IPCB_Polygon;
ruleType?: Array<EPCB_PrimitiveRegionRuleType>;
regionName?: string;
lineWidth?: number;
primitiveLock?: boolean;
},
): Promise<IPCB_PrimitiveRegion | undefined>;1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | IPCB_PrimitiveRegion | Primitive ID |
property | { layer?: TPCB_LayersOfRegion; complexPolygon?: IPCB_Polygon; ruleType?: Array<EPCB_PrimitiveRegionRuleType>; regionName?: string; lineWidth?: number; primitiveLock?: boolean } | Modify Parameter |
Returns
Promise<IPCB_PrimitiveRegion | undefined>
Region primitive object, undefined indicates that the modification failed
Example
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