Home > LIB_LibrariesList > registerExtendLibrary
LIB_LibrariesList.registerExtendLibrary() 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.
Register an external library
Signature
function registerExtendLibrary(
title: string,
libraryFunctions: {
device?: ILIB_ExtendLibraryDeviceFunctions;
symbol?: ILIB_ExtendLibrarySymbolFunctions;
footprint?: ILIB_ExtendLibraryFootprintFunctions;
cbb?: ILIB_ExtendLibraryCbbFunctions;
model3d?: ILIB_ExtendLibrary3DModelFunctions;
},
props?: ILIB_RegisterExtendLibraryProps,
): Promise<string | undefined>;2
3
4
5
6
7
8
9
10
11
Parameters
Parameter | Type | Description |
|---|---|---|
title | string | Title |
libraryFunctions | { device?: ILIB_ExtendLibraryDeviceFunctions; symbol?: ILIB_ExtendLibrarySymbolFunctions; footprint?: ILIB_ExtendLibraryFootprintFunctions; cbb?: ILIB_ExtendLibraryCbbFunctions; model3d?: ILIB_ExtendLibrary3DModelFunctions } | |
props | (Optional) 附加配置,如 saveAs 可分别控制器件、符号、封装等资源是否允许另存为(缺省均允许) |
Returns
Promise<string | undefined>
Library UUID
Remarks
Note: This API is only valid for extensions. Calling it in a standalone script environment will always throw Error
Example
注册外部库并挂载符号类型资源:
// 1. 实现外部库的符号数据回调(真实场景中在此对接自己的数据源)
const symbolFunctions = {
// 分类树:库面板左侧的分类目录
getClassificationTree: async () => [
{ name: '电阻', uuid: 'resistor' },
{ name: '电容', uuid: 'capacitor' }
],
// 列表搜索:响应用户的关键字搜索与分页,返回分页结构
getList: async (props) => {
const all = [{ uuid: 'demo_0402', title: '示例符号 0402' }];
return {
count: all.length,
lists: all,
page: props.page || 1,
pageSize: props.pageSize || 10,
totalPage: 1
};
},
// 详情:用户选中条目后获取完整信息
getDetail: async (uuid) => {
return { uuid, title: '示例符号 0402' };
}
};
// 2. 以指定标题注册外部库,挂载符号类型资源
const libUuid = await eda.lib_LibrariesList.registerExtendLibrary('嘉立创示例_外部库', {
symbol: symbolFunctions
});
// 3. 输出注册结果,库面板中即可看到「嘉立创示例_外部库」
console.log('libUuid:', libUuid);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
28
29
30
31
注册外部库并分别控制各资源类型是否允许另存为(器件允许、符号与封装禁止,缺省的 cbb/model3d 视为允许):
const libUuid = await eda.lib_LibrariesList.registerExtendLibrary(
'嘉立创示例_外部库_另存为控制',
{ device: deviceFunctions, symbol: symbolFunctions, footprint: footprintFunctions },
{
saveAs: {
device: true,
symbol: false,
footprint: false,
},
}
);
console.log('libUuid:', libUuid);2
3
4
5
6
7
8
9
10
11
12