English
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
typescript
function modify(
primitiveId: string | ISCH_PrimitiveComponent,
property: {
x?: number;
y?: number;
rotation?: number;
mirror?: boolean;
addIntoBom?: boolean;
addIntoPcb?: boolean;
designator?: string | null;
name?: string | null;
uniqueId?: string | null;
manufacturer?: string | null;
manufacturerId?: string | null;
supplier?: string | null;
supplierId?: string | null;
subPartName?: string;
symbol?: { uuid?: string; libraryUuid?: string; name?: string } | null;
footprint?: { uuid?: string; libraryUuid?: string; name?: string } | null;
otherProperty?: Record<string, string | number | boolean>;
},
): Promise<ISCH_PrimitiveComponent | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Parameters
Parameter | Type | Description |
|---|---|---|
primitiveId | string | ISCH_PrimitiveComponent | Primitive ID |
property | { x?: number; y?: number; rotation?: number; mirror?: boolean; addIntoBom?: boolean; addIntoPcb?: boolean; designator?: string | null; name?: string | null; uniqueId?: string | null; manufacturer?: string | null; manufacturerId?: string | null; supplier?: string | null; supplierId?: string | null; subPartName?: string; symbol?: { uuid?: string; libraryUuid?: string; name?: string } | null; footprint?: { uuid?: string; libraryUuid?: string; name?: string } | null; otherProperty?: Record<string, string | number | boolean>; } |
Returns
Promise<ISCH_PrimitiveComponent | undefined>
Device primitive object
Remarks
This method can only be used for modification when the device type is COMPONENT
**切换符号与封装**:器件支持绑定多个符号与封装,可通过 的 property.symbol / property.footprint 切换:
- 给出
uuid+libraryUuid时切换到该库内的符号 / 封装; - 只给name(纯文本)时按设置内的**优先库路径** (见 )匹配同名资源; - **主符号**为纯文本时会被自动解析为库内 UUID,**备选符号**为纯文本时保留纯文本、不解析; - 传null表示不修改该项(与其它可清空属性的null语义不同,符号 / 封装不可清空为空)。
Example
javascript
// 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());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
27
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