Home > IPCB_PrimitiveComponent > setAttribute
IPCB_PrimitiveComponent.setAttribute() 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.
Set Property
Signature
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
Parameters
Parameter | Type | Description |
|---|---|---|
key | string | Attribute name. If the device does not have an attribute with this name, the attribute will be added |
value | string | number | boolean | (Optional) Property value |
keyVisible | boolean | (Optional) Attribute name visibility |
valueVisible | boolean | (Optional) Attribute value visibility |
Returns
Promise<IPCB_PrimitiveAttribute>
Attribute primitive object
Example
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