Home > SCH_PrimitiveComponent > modify
SCH_PrimitiveComponent.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 Device
Signature
function modify(
primitiveId: string | ISCH_PrimitiveComponent,
property: {
x?: undefined | number;
y?: undefined | number;
rotation?: undefined | number;
mirror?: undefined | false | true;
addIntoBom?: undefined | false | true;
addIntoPcb?: undefined | false | true;
designator?: undefined | null | string;
name?: undefined | null | string;
uniqueId?: undefined | null | string;
manufacturer?: undefined | null | string;
manufacturerId?: undefined | null | string;
supplier?: undefined | null | string;
supplierId?: undefined | null | string;
otherProperty?: undefined | Record<string, string | number | false | true>;
},
): Promise<ISCH_PrimitiveComponent | undefined>;2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | ISCH_PrimitiveComponent | Primitive ID |
property | { x?: undefined | number; y?: undefined | number; rotation?: undefined | number; mirror?: undefined | false | true; addIntoBom?: undefined | false | true; addIntoPcb?: undefined | false | true; designator?: undefined | null | string; name?: undefined | null | string; uniqueId?: undefined | null | string; manufacturer?: undefined | null | string; manufacturerId?: undefined | null | string; supplier?: undefined | null | string; supplierId?: undefined | null | string; otherProperty?: undefined | Record<string, string | number | false | true> } |
Returns
Promise<ISCH_PrimitiveComponent | undefined>
Device primitive object
Remarks
This method can only be used for modification when the device type is COMPONENT
Example
// 1. 创建待修改的测试器件(随机坐标避免与画布已有器件重合)
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();
// 2. 读取修改前的位号、旋转与 X 坐标
const beforeDesignator = comp.getState_Designator();
const beforeRotation = comp.getState_Rotation();
const beforeX = comp.getState_X();
// 3. 批量修改:右移 400(约 101.6mm)、旋转 90 度、位号改为 U100
await eda.sch_PrimitiveComponent.modify(compId, {
x: x + 400,
rotation: 90,
designator: '嘉立创示例_U100'
});
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.sch_PrimitiveComponent.get(compId);
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', compId);
console.log('designator:', beforeDesignator, '→', refreshed.getState_Designator());
console.log('rotation:', beforeRotation, '→', refreshed.getState_Rotation());
console.log('x:', beforeX, '→', refreshed.getState_X());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