Home > PCB_PrimitiveAttribute > modify
PCB_PrimitiveAttribute.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 Text
Signature
typescript
function modify(
primitiveId: string | IPCB_PrimitiveAttribute,
property: {
layer?: TPCB_LayersOfImage;
x?: number;
y?: number;
key?: string;
value?: string;
keyVisible?: boolean;
valueVisible?: boolean;
fontFamily?: string;
fontSize?: number;
lineWidth?: number;
alignMode?: EPCB_PrimitiveStringAlignMode;
rotation?: number;
reverse?: boolean;
expansion?: number;
mirror?: boolean;
primitiveLock?: boolean;
},
): 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | IPCB_PrimitiveAttribute | Primitive ID |
property | { layer?: TPCB_LayersOfImage; x?: number; y?: number; key?: string; value?: string; keyVisible?: boolean; valueVisible?: boolean; fontFamily?: string; fontSize?: number; lineWidth?: number; alignMode?: EPCB_PrimitiveStringAlignMode; rotation?: number; reverse?: boolean; expansion?: number; mirror?: boolean; primitiveLock?: boolean } | Modify Parameter |
Returns
Promise<IPCB_PrimitiveAttribute | undefined>
Text primitive object
Example
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