Home > PCB_PrimitiveAttribute > modify
PCB_PrimitiveAttribute.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改文本
签名
typescript
function modify(
primitiveId: string | IPCB_PrimitiveAttribute,
property: {
layer?:
| undefined
| EPCB_LayerId.TOP
| EPCB_LayerId.TOP_SILKSCREEN
| EPCB_LayerId.TOP_SOLDER_MASK
| EPCB_LayerId.TOP_ASSEMBLY
| EPCB_LayerId.BOTTOM
| EPCB_LayerId.BOTTOM_SILKSCREEN
| EPCB_LayerId.BOTTOM_SOLDER_MASK
| EPCB_LayerId.BOTTOM_ASSEMBLY
| EPCB_LayerId.DOCUMENT
| EPCB_LayerId.MECHANICAL
| 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
| EPCB_LayerId.CUSTOM_1
| EPCB_LayerId.CUSTOM_2
| EPCB_LayerId.CUSTOM_3
| EPCB_LayerId.CUSTOM_4
| EPCB_LayerId.CUSTOM_5
| EPCB_LayerId.CUSTOM_6
| EPCB_LayerId.CUSTOM_7
| EPCB_LayerId.CUSTOM_8
| EPCB_LayerId.CUSTOM_9
| EPCB_LayerId.CUSTOM_10
| EPCB_LayerId.CUSTOM_11
| EPCB_LayerId.CUSTOM_12
| EPCB_LayerId.CUSTOM_13
| EPCB_LayerId.CUSTOM_14
| EPCB_LayerId.CUSTOM_15
| EPCB_LayerId.CUSTOM_16
| EPCB_LayerId.CUSTOM_17
| EPCB_LayerId.CUSTOM_18
| EPCB_LayerId.CUSTOM_19
| EPCB_LayerId.CUSTOM_20
| EPCB_LayerId.CUSTOM_21
| EPCB_LayerId.CUSTOM_22
| EPCB_LayerId.CUSTOM_23
| EPCB_LayerId.CUSTOM_24
| EPCB_LayerId.CUSTOM_25
| EPCB_LayerId.CUSTOM_26
| EPCB_LayerId.CUSTOM_27
| EPCB_LayerId.CUSTOM_28
| EPCB_LayerId.CUSTOM_29
| EPCB_LayerId.CUSTOM_30
| EPCB_LayerId.DRILL_DRAWING;
x?: undefined | number;
y?: undefined | number;
key?: undefined | string;
value?: undefined | string;
keyVisible?: undefined | false | true;
valueVisible?: undefined | false | true;
fontFamily?: undefined | string;
fontSize?: undefined | number;
lineWidth?: undefined | number;
alignMode?:
| undefined
| EPCB_PrimitiveStringAlignMode.LEFT_TOP
| EPCB_PrimitiveStringAlignMode.LEFT_MIDDLE
| EPCB_PrimitiveStringAlignMode.LEFT_BOTTOM
| EPCB_PrimitiveStringAlignMode.CENTER_TOP
| EPCB_PrimitiveStringAlignMode.CENTER
| EPCB_PrimitiveStringAlignMode.CENTER_BOTTOM
| EPCB_PrimitiveStringAlignMode.RIGHT_TOP
| EPCB_PrimitiveStringAlignMode.RIGHT_MIDDLE
| EPCB_PrimitiveStringAlignMode.RIGHT_BOTTOM;
rotation?: undefined | number;
reverse?: undefined | false | true;
expansion?: undefined | number;
mirror?: undefined | false | true;
primitiveLock?: undefined | false | true;
},
): Promise<IPCB_PrimitiveAttribute | 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
参数名
返回值
Promise<IPCB_PrimitiveAttribute | undefined>
文本图元对象
示例
javascript
// 1. 放置测试器件并添加自定义属性(随机坐标避免与画布已有器件重合):
// 按立创编号从系统库精确反查器件,返回项不含 libraryUuid,需补上才能用于 create
const x = 20000 + Math.floor(Math.random() * 80000);
const y = 20000 + Math.floor(Math.random() * 80000);
const devices = await eda.lib_Device.searchByProperties({ supplierId: 'C1523' }, undefined, undefined, undefined, 5, 1);
const sysLibUuid = await eda.lib_LibrariesList.getSystemLibraryUuid();
const comp = await eda.pcb_PrimitiveComponent.create({ libraryUuid: sysLibUuid, uuid: devices[0].uuid }, 1, x, y);
const compId = comp.getState_PrimitiveId();
await comp.setAttribute('嘉立创示例_Tolerance', '1%', true, true);
// 2. 找到自定义属性的图元并读取修改前的值
const attrIds = await eda.pcb_PrimitiveAttribute.getAllPrimitiveId(compId);
const attrs = await eda.pcb_PrimitiveAttribute.get(attrIds);
const target = attrs.find(a => a.getState_Key() === '嘉立创示例_Tolerance');
const beforeValue = target.getState_Value();
const beforeFontSize = target.getState_FontSize();
// 3. 批量修改:属性值 1% → 5%,字号 45 → 60
await eda.pcb_PrimitiveAttribute.modify(target.getState_PrimitiveId(), { value: '5%', fontSize: 60 });
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.pcb_PrimitiveAttribute.get(target.getState_PrimitiveId());
// 5. 修改类保留现场,供观察修改结果
console.log('value:', beforeValue, '→', refreshed.getState_Value());
console.log('fontSize:', beforeFontSize, '→', refreshed.getState_FontSize());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
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