Home > LIB_Device > copy
LIB_Device.copy() 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.
Copy Device
Signature
typescript
function copy(
deviceUuid: string,
libraryUuid: string,
targetLibraryUuid: string,
targetClassification?: ILIB_ClassificationIndex | Array<string>,
newDeviceName?: string,
): Promise<string | undefined>;1
2
3
4
5
6
7
2
3
4
5
6
7
Parameters
Parameter | Type | Description |
|---|---|---|
deviceUuid | string | Device UUID |
libraryUuid | string | Library UUID, you can use LIB_LibrariesList APIs in |
targetLibraryUuid | string | Target library UUID |
targetClassification | ILIB_ClassificationIndex | Array<string> | (Optional) Classification in the target library |
newDeviceName | string | (Optional) New device name. If a device with the same name exists in the target library, the copy will fail |
Returns
Promise<string | undefined>
UUID of the new device in the target library
Example
javascript
// 1. 获取个人库 UUID
const libraryUuid = await eda.lib_LibrariesList.getPersonalLibraryUuid();
// 2. 新建一个轻量器件作为复制来源
const sourceName = `嘉立创示例_复制源_${Date.now()}`;
const sourceUuid = await eda.lib_Device.create(libraryUuid, sourceName, [], { symbolType: 2 });
// 3. 复制到同一库,指定新名称避免同名冲突(分类传 [] = 不分类)
const newName = `嘉立创示例_复制品_${Date.now()}`;
const copiedUuid = await eda.lib_Device.copy(sourceUuid, libraryUuid, libraryUuid, [], newName);
// 创建类保留现场(原件与复制品都留在个人库中供观察)
console.log('sourceUuid:', sourceUuid);
console.log('copiedUuid:', copiedUuid);
console.log('newName:', newName);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16