Home > LIB_Symbol > updateDocumentSource
LIB_Symbol.updateDocumentSource() 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.
Update the document source code of the symbol
Signature
typescript
function updateDocumentSource(
symbolUuid: string,
libraryUuid: string,
documentSource: string,
): Promise<boolean | undefined>;1
2
3
4
5
2
3
4
5
Parameters
Parameter | Type | Description |
|---|---|---|
symbolUuid | string | Symbol UUID |
libraryUuid | string | Library UUID, you can use LIB_LibrariesList APIs in |
documentSource | string | Document source code |
Returns
Promise<boolean | undefined>
Whether the update is successful
Example
javascript
// 1. 获取个人库 UUID,从系统库复制一个符号(有内容,源码链路才完整)
const libraryUuid = await eda.lib_LibrariesList.getPersonalLibraryUuid();
const [source] = await eda.lib_Symbol.search('', undefined, [], undefined, 1, 1);
const symbolUuid = await eda.lib_Symbol.copy(
source.uuid,
source.libraryUuid,
libraryUuid,
[],
`嘉立创示例_源码符号_${Date.now()}`
);
// 2. 在编辑器中打开符号,等待文档加载完成
const tabId = await eda.lib_Symbol.openInEditor(symbolUuid, libraryUuid);
await new Promise(r => setTimeout(r, 1500));
// 3. 读取当前打开符号的文档源码
const documentSource = await eda.sys_FileManager.getDocumentSource();
// 4. 把源码写回库中的符号(此处原样写回;实际使用时可先改写 documentSource)
const updated = await eda.lib_Symbol.updateDocumentSource(symbolUuid, libraryUuid, documentSource);
// 5. 关闭编辑器标签页(符号本体保留在库中)
await eda.dmt_EditorControl.closeDocument(tabId);
// 修改类保留现场
console.log('symbolUuid:', symbolUuid);
console.log('sourceLength:', documentSource.length);
console.log('updated:', updated);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
28
29
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