Home > SCH_PrimitiveComponent > modify
SCH_PrimitiveComponent.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改器件
签名
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
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveId | string | ISCH_PrimitiveComponent | 图元 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> } |
返回值
Promise<ISCH_PrimitiveComponent | undefined>
器件图元对象
备注
仅当器件类型为 COMPONENT 时允许使用该方法进行修改
示例
// 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