Home > SCH_PrimitiveAttribute > modify
SCH_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 Property
Signature
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>;2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | ISCH_PrimitiveAttribute | Primitive 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 } | Modify Parameter |
Returns
Promise<ISCH_PrimitiveAttribute | undefined>
Attribute primitive object
Example
// 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());2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23