Home > IPCB_PrimitiveComponent > setAttribute
IPCB_PrimitiveComponent.setAttribute() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
设置属性
签名
typescript
function setAttribute(
key: string,
value?: string | number | boolean,
keyVisible?: boolean,
valueVisible?: boolean,
): Promise<IPCB_PrimitiveAttribute>;1
2
3
4
5
6
2
3
4
5
6
参数名
参数 | 类型 | 描述 |
|---|---|---|
key | string | 属性名,如若器件不存在该属性名的属性,将会新增该属性 |
value | string | number | boolean | (可选) 属性值 |
keyVisible | boolean | (可选) 属性名可见性 |
valueVisible | boolean | (可选) 属性值可见性 |
返回值
Promise<IPCB_PrimitiveAttribute>
属性图元对象
示例
javascript
// 1. 生成本次运行专用的坐标,避免与之前保留的测试器件重合
const x = 20000 + Math.floor(Math.random() * 80000);
const y = 20000 + Math.floor(Math.random() * 80000);
// 2. 放置测试器件
const devices = await eda.lib_Device.search('C0402');
const comp = await eda.pcb_PrimitiveComponent.create(devices[0], 1, x, y);
const compId = comp.getState_PrimitiveId();
// 3. 设置自定义属性(属性名、属性值、名称可见、值可见)
await comp.setAttribute('嘉立创示例_Tolerance', '1%', true, true);
// 4. 通过属性图元接口确认属性已写入(保留现场供观察)
const attrIds = await eda.pcb_PrimitiveAttribute.getAllPrimitiveId(compId);
const attrs = await eda.pcb_PrimitiveAttribute.get(attrIds);
const added = attrs.find(a => a.getState_Key() === '嘉立创示例_Tolerance');
console.log('attrKey:', added.getState_Key());
console.log('attrValue:', added.getState_Value());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19