Skip to content

Commit

Permalink
Merge pull request #843 from PandaNocturne/24.08.19_Panda
Browse files Browse the repository at this point in the history
提交一篇Excalidraw脚本文档
  • Loading branch information
juestchaos authored Aug 19, 2024
2 parents 0dfdf21 + 950c028 commit beb6b77
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,52 @@ https://raw.githubusercontent.com/PandaNocturne/ExcalidrawScripts/master/PandaSc
> - [BookxNoteToObsidian - by 熊猫别熬夜 - 动作信息 - Quicker](https://getquicker.net/Sharedaction?code=2bd5ec90-db36-49d4-51b3-08db7dd91f1a)
> - ![2024-03-06_熊猫别熬夜Excalidraw脚本汇总-Excalidraw自动检测更新_IMG-29](https://cdn.pkmer.cn/images/202404012157083.png!pkmer)

### EagleToExcalidraw

```excalidraw-script-install
https://raw.githubusercontent.com/PandaNocturne/ExcalidrawScripts/master/PandaScripts/EagleToExcalidraw.md
```

- Author:熊猫别熬夜
- PKMerDoc:[[自定义Excalidraw脚本-建立库外Eagle素材库的连接]]
- PKMerDoc:[自定义 Excalidraw 脚本 - 建立库外 Eagle 素材库的连接](https://pkmer.cn/show/20231014173618)
- Description:实现 Eagle 与 Excalidraw 的联动,可导入素材并定位到 Eagle 具体位置,暂时还没做发送 Excalidraw 的图片到 Eagle。
- ChangeLog:
- 24.08.17
- 可选中 Excalidraw 中局部元素发送到 Eagle
- ![File-20240817110840973.png](https://cdn.pkmer.cn/images/202408190105322.png!pkmer)
- 添加启动和关闭模式选项
- ![File-20240817110929916.png](https://cdn.pkmer.cn/images/202408190105360.png!pkmer)
- 从 Eagle 导入到 Excalidraw 的文件自动添加 `Eagle→Excalidraw` 标签

> Zotero 与 Eagle 的联动我也有一点尝试:
> - [[Quicker动作之发送Zotero图片标注至Eagle素材库]]
> - [ZoteroToEagle - by 熊猫别熬夜 - 动作信息 - Quicker](https://getquicker.net/Sharedaction?code=85b92307-2003-47bd-afea-08dc426a44c3)
> - ![2024-03-06_熊猫别熬夜Excalidraw脚本汇总-Excalidraw自动检测更新_IMG-30](https://cdn.pkmer.cn/images/202404012157084.png!pkmer)
> - [ZoteroToEagle - by 熊猫别熬夜 - 动作信息 - Quicker](https://getquicker.net/Sharedaction?code=85b92307-2003-47bd-afea-08dc426a44c3)
> - ![File-20240426045317722.png](https://cdn.pkmer.cn/images/202408190105055.png!pkmer)
### ShareToEagle

```excalidraw-script-install
https://raw.githubusercontent.com/PandaNocturne/ExcalidrawScripts/master/PandaScripts/ShareToEagle.md
```

- Author:熊猫别熬夜
- PKMerDoc:[[自定义Excalidraw脚本-保存局部视图至Eagle并实现二次编辑功能]]
- Description:可选中 Excalidraw 中局部元素发送到 Eagle,已集合到EagleToExcalidraw脚本中,该脚本单独将此功能分离出来,导入Eagle里面的格式是SVG,可在官方Excalidraw中还原并二次编辑。
- ![File-20240817110840973.png](https://cdn.pkmer.cn/images/202408190105147.png!pkmer)
- ![PixPin_2024-08-18_12-37-11.gif](https://cdn.pkmer.cn/images/202408190105015.gif!pkmer)
- ![PixPin_2024-08-18_12-37-40.gif](https://cdn.pkmer.cn/images/202408190105549.gif!pkmer)

## 社区分享的脚本

### 统计选中图层字数 (Word Counter)

```excalidraw-script-install
https://raw.githubusercontent.com/wish5115/my-softs/main/Excalidraw/Words%20Counter.md
```

- Author: wilson
- ObsidianDoc: [Excalidraw脚本统计选中图层字数 - 经验分享 - Obsidian 中文论坛](https://forum-zh.obsidian.md/t/topic/36490/2)
- Description:选中要统计的图层,点击插件按钮”123“图标,即弹出统计通知
- ![File-20240709110928305.png](https://cdn.pkmer.cn/images/202408190107560.png!pkmer)
- 统计逻辑:一个英文单词算一个,一个中文文字算一个,一个空格或标点符号算一个。

Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
---
uid: 20240819010803
title: 自定义 Excalidraw 脚本 - 保存局部视图至 Eagle 并实现二次编辑功能
tags: [Excalidraw脚本, Eagle]
description: 可选中 Excalidraw 中局部元素发送到 Eagle(),导入 Eagle 里面的格式是 SVG,导入时可设置 SVG 名称,标签,Obsidian 文档链接,Eagle 中的 SVG 可在官方 Excalidraw 中还原。
author: 熊猫别熬夜
type: other
draft: false
editable: false
modified: 20240819011249
---

# 自定义 Excalidraw 脚本 - 保存局部视图至 Eagle 并实现二次编辑功能

可选中 Excalidraw 中局部元素发送到 Eagle(),导入 Eagle 里面的格式是 SVG,导入时可设置 SVG 名称,标签,Obsidian 文档链接,Eagle 中的 SVG 可在官方 Excalidraw 中还原。

![自定义Excalidraw脚本-保存局部视图至Eagle并实现二次编辑功能](https://cdn.pkmer.cn/images/202408190108348.png!pkmer)

> 注:该脚本已集合到 EagleToExcalidraw 脚本中,选中多个 Excalidraw 画板中的元素再运行既可触发。
## 脚本安装

> 详细步骤参考:[熊猫别熬夜 Excalidraw 脚本汇总介绍](https://pkmer.cn/show/20240323225915 )
安装链接及代码块:

````md
```excalidraw-script-install
https://raw.githubusercontent.com/PandaNocturne/ExcalidrawScripts/master/PandaScripts/ShareToEagle.md
```
````

## 功能演示

![PixPin_2024-08-18_12-37-11.gif](https://cdn.pkmer.cn/images/202408190108100.gif!pkmer)

在 Excalidraw 画布中框选中你想要保存的区域后,运行该脚本,就会弹出对话框,可以设置 SVG 名称,注释,标签,Ob 文档链接 (需要 Advanced URI 插件),确认后既可发送至 Eagle 中。

![自定义Excalidraw脚本-保存局部视图至Eagle并实现二次编辑功能](https://cdn.pkmer.cn/images/202408190108348.png!pkmer)

### Tip:Excalidraw 的 SVG 格式可在官方 Excalidraw 中二次编辑

保存在 Eagle 中的 Excalidraw 的局部视图格式为 SVG 格式,可以拖到官方 Excalidraw 还原为原 Excalidraw 数据来二次编辑。

![自定义Excalidraw脚本-保存局部视图至Eagle并实现二次编辑功能](https://cdn.pkmer.cn/images/202408190108220.gif!pkmer)

## 拓展文档

- [[自定义Excalidraw脚本-建立库外Eagle素材库的连接]]
- [[自定义Excalidraw脚本-将选中元素为PNG或者SVG格式文件到本地]]
- [[Quicker动作之发送Zotero图片标注至Eagle素材库]]

## 源代码

```js
/*
* @Author: 熊猫别熬夜
* @Date: 2024-08-19 00:32:03
* @Last Modified by: 熊猫别熬夜
* @Last Modified time: 2024-08-19 00:32:03
*/
// 获取选中元素否则为全部元素
let elements = ea.getViewSelectedElements();
const allEls = ea.getViewElements();

if (elements.length === 0) {
elements = allEls;
ea.selectElementsInView(elements);
}

// 如果选中元素中包含frame,则自动选择内部元素
var frameEls = [];
for (let el of elements) {
if (el.type === "frame") {
for (let i of allEls) {
if (i.frameId === el.id) {
frameEls.push(i);
}
}
}
}
ea.selectElementsInView([...elements, ...frameEls]);

// 获取笔记的基本路径
const basename = app.workspace.getActiveFile().basename;
let date = window.moment().format("YYYYMMDDHHmmss");

let base64 = "";
await ea.targetView.svg(ea.targetView.getScene(true), undefined, true).then(svg => {
base64 = `data:image/svg+xml;base64,${btoa(
unescape(encodeURIComponent(svg.outerHTML)),
)}`;
});

// =========== 配置 =========== //
const data = {
"url": base64,
"name": `EX-${date}`,
"website": "",
"tags": ["Excalidraw→Eagle"],
"annotation": "",
"folderId": "" // 图片将会添加到指定文件夹的Eagle的FolderID
};
let returnLinkEnabled = true;
// 配置按钮
const customControls = (container) => {
new ea.obsidian.Setting(container)
.setName(`SVG名称`)
.addText(text => {
text
.setValue(data.name)
.onChange(value => {
data.name = value;
});
});
new ea.obsidian.Setting(container)
.setName(`Eagle标签`)
.setDesc(`用英文逗号(,)分隔标签`) // 添加描述
.addText(text => {
text
.setValue(data.tags.join(',')) // 数组转逗号分隔的字符串
.onChange(value => {
data.tags = value.split(','); // 逗号分隔的字符串转数组
});
});
new ea.obsidian.Setting(container)
.setName(`返回链接`)
.setDesc(`启用或禁用Ob链接,需要Advanced URI插件`)
.addToggle(toggle => {
toggle
.setValue(returnLinkEnabled) // 默认值为true
.onChange(value => {
returnLinkEnabled = value; // 更新data对象中的属性

});
});

};

if (returnLinkEnabled) {
const vaultName = app.vault.getName();
const activeFile = app.workspace.getActiveFile();
const ctime = await app.vault.getAbstractFileByPath(activeFile.path).stat["ctime"];
const uidFormat = "YYYYMMDDhhmmssSSS";
let adURI = "";
await app.fileManager.processFrontMatter(activeFile, fm => {
adURI = fm.uid ? fm.uid : moment(ctime).format(uidFormat);
fm.uid = moment(ctime).format(uidFormat);
});
await ea.addElementsToView();
data.website = `obsidian://advanced-uri?vault=${vaultName}&uid=${adURI}`;
}

let isSend = false;
data.annotation = await utils.inputPrompt(
"导入Eagle的注释",
"发送至Eagle的SVG的注释",
"",
[
{
caption: "Confirm",
action: () => { isSend = true; return; }
},
],
5,
false,
customControls
);
if (!isSend) return;


const requestOptions = {
method: 'POST',
body: JSON.stringify(data),
redirect: 'follow'
};

let response;
fetch("http://localhost:41595/api/item/addFromURL", requestOptions)
.then(response => response.json())
.then(result => {
console.log(result);
new Notice("📤已成功发送到Eagle!"); // 成功后显示通知
})
.catch(error => console.log('error', error));

```
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ modified: 20240720191115
## CSS 样式

```css
/* 2024-04-04_21:48:参考:https://gist.github.com/digitalsignalperson/56fe3cbcf41707cb97362234cb07ccb0 */
/* 2024-04-04_21:48:来源:https://gist.github.com/digitalsignalperson/56fe3cbcf41707cb97362234cb07ccb0 */

/* 启动BFC */
.workspace .mod-root .workspace-tab-header-container.workspace-tab-header-container.workspace-tab-header-container {
display: table;
position: relative;
padding-left: 8px;
padding-right: 12px;
padding-right: 80px;
}

.workspace .mod-root .workspace-tab-header-container-inner {
Expand Down Expand Up @@ -115,16 +115,16 @@ modified: 20240720191115
.mod-root .workspace-tab-header-new-tab {
display: inline-block;
position: absolute;
top: 0px !important;
right: 25px !important;
top: 0px;
right: 70px;
}

/* !下拉菜单调整 */
.workspace-tab-header-tab-list {
display: block;
position: absolute;
top: 0px !important;
right: 0px !important;
top: 0px;
right: 45px;
}

/* bug修复 */
Expand All @@ -134,8 +134,21 @@ modified: 20240720191115
}

/* 常驻显示关闭按钮 */
.workspace .mod-root .workspace-tab-header:not(.mod-stacked) .workspace-tab-header-inner-close-button {
display: flex !important;
.workspace.workspace.workspace .mod-root .workspace-tab-header:not(.mod-stacked) .workspace-tab-header-inner-close-button {
display: flex;
}

.workspace-tab-header-container>.sidebar-toggle-button.mod-right{
/* display: inline-block; */
top: 0px;
position: absolute;
right: 10px;
z-index: 1;
}

/* 不显示顶部按钮 */
.titlebar-button-container.mod-right{
display: none;
}

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Excalidraw 在早期是有很多问题的,比如没有手写压感,插图太

> EA 脚本开发的介绍: [[ExcalidrawAutomate index]]
- [[熊猫别熬夜Excalidraw脚本汇总-Excalidraw自动检测更新]]
- [[熊猫别熬夜Excalidraw脚本汇总]]

### CSS 美化

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ module.exports = {
## Reference

1. [[关于 Diagram 软件的功能介绍以及在 Obsidian 使用的方案]]
2. [[熊猫别熬夜Excalidraw脚本汇总-Excalidraw自动检测更新]]
2. [[熊猫别熬夜Excalidraw脚本汇总]]
3. [【QuickAdd脚本】通过wiki链接删除并对应文件,适用于笔记重组 - 经验分享 - Obsidian 中文论坛](https://forum-zh.obsidian.md/t/topic/31660)

0 comments on commit beb6b77

Please sign in to comment.