From 5692006d19a01be734f91c1907ebee102027ba8c Mon Sep 17 00:00:00 2001 From: Zsolt Viczian Date: Sun, 12 Dec 2021 07:43:27 +0100 Subject: [PATCH] script changes --- docs/ExcalidrawScriptsEngine.md | 16 ++++++++++++---- ea-scripts/Box Selected Elements.md | 12 +++++++++--- ea-scripts/Stroke Width.md | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/ExcalidrawScriptsEngine.md b/docs/ExcalidrawScriptsEngine.md index 9700179..f2b318d 100644 --- a/docs/ExcalidrawScriptsEngine.md +++ b/docs/ExcalidrawScriptsEngine.md @@ -28,11 +28,18 @@ An Excalidraw script will automatically receive two objects: ### Add box around selected elements This script will add an encapsulating box around the currently selected elements in Excalidraw ```javascript -padding = parseInt (await utils.inputPrompt("padding?")); +//uncomment if you want a prompt for custom padding +//const padding = parseInt (await utils.inputPrompt("padding?","number","10")); +const padding = 10 elements = ea.getViewSelectedElements(); const box = ea.getBoundingBox(elements); -const rndColor = '#'+(Math.random()*0xFFFFFF<<0).toString(16).padStart(6,"0"); -ea.style.strokeColor = rndColor; +color = ea + .getExcalidrawAPI() + .getAppState() + .currentItemStrokeColor; +//uncomment if you want to set the stroke to a random color +//color = '#'+(Math.random()*0xFFFFFF<<0).toString(16).padStart(6,"0"); +ea.style.strokeColor = color; id = ea.addRect( box.topX - padding, box.topY - padding, @@ -68,7 +75,8 @@ ea.addElementsToView(); ### Set line width of selected elements This is helpful, for example, when you scale freedraw sketches and want to reduce or increase their line width. ```javascript -width = await utils.inputPrompt("Width?"); +let width = (ea.getViewSelectedElement().strokeWidth??1).toString(); +width = await utils.inputPrompt("Width?","number",width); const elements=ea.getViewSelectedElements(); ea.copyViewElementsToEAforEditing(elements); ea.getElements().forEach((el)=>el.strokeWidth=width); diff --git a/ea-scripts/Box Selected Elements.md b/ea-scripts/Box Selected Elements.md index 8e15e43..f67ba15 100644 --- a/ea-scripts/Box Selected Elements.md +++ b/ea-scripts/Box Selected Elements.md @@ -8,12 +8,18 @@ https://zsviczian.github.io/obsidian-excalidraw-plugin/ExcalidrawScriptsEngine.h ```javascript */ -//const padding = parseInt (await utils.inputPrompt("padding?")); +//uncomment if you want a prompt for custom padding +//const padding = parseInt (await utils.inputPrompt("padding?","number","10")); const padding = 10 elements = ea.getViewSelectedElements(); const box = ea.getBoundingBox(elements); -const rndColor = '#'+(Math.random()*0xFFFFFF<<0).toString(16).padStart(6,"0"); -ea.style.strokeColor = rndColor; +color = ea + .getExcalidrawAPI() + .getAppState() + .currentItemStrokeColor; +//uncomment for random color: +//color = '#'+(Math.random()*0xFFFFFF<<0).toString(16).padStart(6,"0"); +ea.style.strokeColor = color; id = ea.addRect( box.topX - padding, box.topY - padding, diff --git a/ea-scripts/Stroke Width.md b/ea-scripts/Stroke Width.md index a693797..bcb5528 100644 --- a/ea-scripts/Stroke Width.md +++ b/ea-scripts/Stroke Width.md @@ -8,7 +8,8 @@ https://zsviczian.github.io/obsidian-excalidraw-plugin/ExcalidrawScriptsEngine.h ```javascript */ -width = await utils.inputPrompt("Width?"); +let width = (ea.getViewSelectedElement().strokeWidth??1).toString(); +width = await utils.inputPrompt("Width?","number",width); const elements=ea.getViewSelectedElements(); ea.copyViewElementsToEAforEditing(elements); ea.getElements().forEach((el)=>el.strokeWidth=width);