Home > SCH_PrimitiveAttribute > modify
SCH_PrimitiveAttribute.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改属性
签名
typescript
function modify(
primitiveId: string | ISCH_PrimitiveAttribute,
property: {
x?: number | null;
y?: number | null;
rotation?: number | null;
color?: string | null;
fontName?: string | null;
fontSize?: number | null;
bold?: boolean | null;
italic?: boolean | null;
underLine?: boolean | null;
alignMode?: ESCH_PrimitiveTextAlignMode | null;
fillColor?: string | null;
key?: string;
value?: string;
keyVisible?: boolean | null;
valueVisible?: boolean | null;
},
): Promise<ISCH_PrimitiveAttribute | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveId | string | ISCH_PrimitiveAttribute | 图元 ID |
property | { x?: number | null; y?: number | null; rotation?: number | null; color?: string | null; fontName?: string | null; fontSize?: number | null; bold?: boolean | null; italic?: boolean | null; underLine?: boolean | null; alignMode?: ESCH_PrimitiveTextAlignMode | null; fillColor?: string | null; key?: string; value?: string; keyVisible?: boolean | null; valueVisible?: boolean | null } | 修改参数 |
返回值
Promise<ISCH_PrimitiveAttribute | undefined>
属性图元对象
示例
javascript
// 1. 放置一个测试器件并定位 Designator(编号)属性
const devices = await eda.lib_Device.search('');
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
const comp = await eda.sch_PrimitiveComponent.create(devices[0], x, y);
const compId = comp.getState_PrimitiveId();
const attrIds = await eda.sch_PrimitiveAttribute.getAllPrimitiveId(compId);
const attrs = await eda.sch_PrimitiveAttribute.get(attrIds);
const designator = attrs.find(a => a.getState_Key() === 'Designator');
// 2. 读取修改前的位号
const before = designator.getState_Value();
// 3. 批量修改:位号改为 C900,同时加粗显示
await eda.sch_PrimitiveAttribute.modify(designator.getState_PrimitiveId(), { value: 'C900', bold: true });
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = (await eda.sch_PrimitiveAttribute.get(attrIds)).find(a => a.getState_Key() === 'Designator');
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', designator.getState_PrimitiveId());
console.log('value:', before, '→', refreshed.getState_Value());
console.log('bold:', refreshed.getState_Bold());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23